Skip to content

Commit

Permalink
fix NA handling, improve graph
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelsoup42 committed Oct 9, 2023
1 parent 53e74f9 commit a510fd6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
15 changes: 6 additions & 9 deletions src/cardano_account_pandas_dumper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import matplotlib.pyplot as plt
from blockfrost import ApiError, BlockFrostApi
from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE

from .cardano_account_pandas_dumper import AccountData, AccountPandasDumper

# Error codes due to project key rate limiting or capping
Expand Down Expand Up @@ -106,12 +105,6 @@ def _create_arg_parser():
default=True,
type=bool,
)
result.add_argument(
"--zero_is_nan",
help="Convert zero values to NaN in spreadsheet (to display empty cells instead of 0).",
default=True,
type=bool,
)
return result


Expand Down Expand Up @@ -214,7 +207,6 @@ def main():
try:
frame = reporter.make_transaction_frame(
with_total=args.with_total,
zero_is_nan=args.zero_is_nan,
text_cleaner=lambda x: ILLEGAL_CHARACTERS_RE.sub(
lambda y: "".join(
["\\x0" + hex(ord(y.group(0))).removeprefix("0x")]
Expand All @@ -235,9 +227,14 @@ def main():
except OSError as exception:
warnings.warn(f"Failed to write .xlsx file: {exception}")
if args.plot:
plt.figure(layout="constrained")
balance = reporter.make_balance_frame(with_total=False).cumsum()
balance.plot(logy=True)
plt.legend(
bbox_to_anchor=(1, 1),
fontsize="small",
)
plt.suptitle(f"Asset balances until block {args.to_block}.")
plt.show()
print("Done.")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ def make_balance_frame(
else:
group = (0, 2)
balance = balance.T.groupby(level=group).sum(numeric_only=True).T
balance[balance == 0] = pd.NA
if with_total:
balance = pd.concat(
[
Expand Down Expand Up @@ -541,7 +542,6 @@ def make_balance_frame(

def make_transaction_frame(
self,
zero_is_nan: bool = True,
with_total: bool = True,
text_cleaner: Callable = lambda x: x,
) -> pd.DataFrame:
Expand Down Expand Up @@ -582,6 +582,4 @@ def make_transaction_frame(
balance_frame
), f"Frame lengths do not match {msg_frame=!s} , {balance_frame=!s}"
joined_frame = pd.concat(objs=[msg_frame, balance_frame], axis=1)
if zero_is_nan:
joined_frame.replace(np.float64(0), pd.NA, inplace=True)
return joined_frame

0 comments on commit a510fd6

Please sign in to comment.