diff --git a/src/cardano_account_pandas_dumper/__main__.py b/src/cardano_account_pandas_dumper/__main__.py index 2be9c96..183e9f4 100644 --- a/src/cardano_account_pandas_dumper/__main__.py +++ b/src/cardano_account_pandas_dumper/__main__.py @@ -6,6 +6,7 @@ from json import JSONDecodeError import jstyleson +import pandas as pd from blockfrost import ApiError, BlockFrostApi from .cardano_account_pandas_dumper import AccountData, AccountPandasDumper @@ -159,7 +160,13 @@ def main(): reporter = AccountPandasDumper( data=data_from_api, known_dict=known_dict_from_file, args=args ) - dataframe = reporter.make_transaction_frame() + transactions = pd.concat( + objs=[ + data_from_api.transactions, + pd.Series() if args.no_rewards else data_from_api.reward_transactions, + ], + ).rename("transactions") + dataframe = reporter.make_transaction_frame(transactions) if args.pandas_output: try: dataframe.to_pickle(args.pandas_output) diff --git a/src/cardano_account_pandas_dumper/cardano_account_pandas_dumper.py b/src/cardano_account_pandas_dumper/cardano_account_pandas_dumper.py index a4188bb..9abc33e 100644 --- a/src/cardano_account_pandas_dumper/cardano_account_pandas_dumper.py +++ b/src/cardano_account_pandas_dumper/cardano_account_pandas_dumper.py @@ -436,7 +436,12 @@ def _drop_muted_policies(self, balance: pd.DataFrame) -> None: balance.sort_index(inplace=True, axis=1) balance.drop(policies_to_drop, axis=1, inplace=True) - def make_transaction_frame(self) -> pd.DataFrame: + def make_transaction_frame( + self, + transactions: pd.Series, + with_tx_hash: bool = True, + with_tx_message: bool = True, + ) -> pd.DataFrame: """Build a transaction spreadsheet.""" # Add total line at the bottom @@ -451,17 +456,13 @@ def make_transaction_frame(self) -> pd.DataFrame: # ) # ) # outputs.loc["Total"] = total - transactions = pd.concat( - objs=[ - self.data.transactions, - pd.Series() if self.args.no_rewards else self.data.reward_transactions, - ], - ).rename("transactions") - timestamp = transactions.rename("timestamp").map(self._extract_timestamp) - tx_hash = transactions.rename("hash").map(lambda x: x.hash) - message = transactions.rename("message").map(self._format_message) + columns = [transactions.rename("timestamp").map(self._extract_timestamp)] + if with_tx_hash: + columns.append(transactions.rename("hash").map(lambda x: x.hash)) + if with_tx_message: + columns.append(transactions.rename("message").map(self._format_message)) balance = self.make_balance_frame(transactions) - frame = pd.concat([timestamp, tx_hash, message], axis=1) + frame = pd.concat(columns, axis=1) frame.reset_index(drop=True, inplace=True) frame.columns = pd.MultiIndex.from_tuples( [ @@ -474,6 +475,7 @@ def make_transaction_frame(self) -> pd.DataFrame: return frame def make_balance_frame(self, transactions): + """Make DataFrame with transaction balances.""" balance = pd.DataFrame( data=[self._transaction_balance(x) for x in transactions], dtype="Int64",