Skip to content

Commit

Permalink
use asset scale instead of decimals, fix metadata column header
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelsoup42 committed Oct 5, 2023
1 parent 7ae4f7f commit 23caf3a
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/cardano_account_pandas_dumper/cardano_account_pandas_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,17 @@ def __init__(
{asset.asset: self._decode_asset_name(asset) for asset in self.data.assets}
| {self.ADA_ASSET: self.ADA_ASSET}
)
self.asset_decimals = pd.Series(
self.asset_scale = pd.Series(
{
asset.asset: np.longlong(asset.metadata.decimals or 0)
if hasattr(asset, "metadata") and hasattr(asset.metadata, "decimals")
else 0
asset.asset: np.float_power(
10,
np.negative(
np.longlong(asset.metadata.decimals or 0)
if hasattr(asset, "metadata")
and hasattr(asset.metadata, "decimals")
else 0
),
)
for asset in self.data.assets
}
| {self.ADA_ASSET: self.ADA_DECIMALS}
Expand Down Expand Up @@ -490,10 +496,7 @@ def make_balance_frame(
.T
)

balance = balance * [
np.float_power(10, np.negative(self.asset_decimals[c[0]]))
for c in balance.columns
]
balance = balance * [self.asset_scale[c[0]] for c in balance.columns]
if not self.raw_values:
balance.columns = pd.MultiIndex.from_tuples(
[(text_cleaner(self.asset_names[c[0]]), c[1]) for c in balance.columns]
Expand Down Expand Up @@ -521,7 +524,7 @@ def make_transaction_frame(
balance_frame = self.make_balance_frame(text_cleaner=text_cleaner)
msg_frame.columns = pd.MultiIndex.from_tuples(
[
("metadata", c) + (len(balance_frame.columns[0]) - 2) * ("",)
(c,) + (len(balance_frame.columns[0]) - 1) * ("",)
for c in msg_frame.columns
]
)
Expand Down

0 comments on commit 23caf3a

Please sign in to comment.