Skip to content

Commit c2353f7

Browse files
committed
fixed issue with "nan" being displayed in table for non-existing locales
closes #11
1 parent 40c74a0 commit c2353f7

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ e.g. a good starting point is [list_accounts.py](https://github.com/ma4nn/pp-ter
106106

107107
The app uses [Typer](https://typer.tiangolo.com/) for composing the commands and [Rich](https://github.com/Textualize/rich)
108108
for nice console outputs. The Portfolio Performance XML file is read with [ppxml2db](https://github.com/pfalcon/ppxml2db)
109-
and efficiently held in [panda dataframes](https://pandas.pydata.org/).
109+
and efficiently held in [pandas dataframes](https://pandas.pydata.org/).
110110

111111
If your command makes sense for a broader audience, I'm happy to accept a pull request.
112112

pp_terminal/helper.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ def currency_exists(currency_code: str, locale: str | None = None) -> bool:
3838

3939

4040
def format_money(value: Money, currency: str = '', locale: str | None = babel.numbers.LC_NUMERIC) -> str:
41+
if pd.isna(value) or not isinstance(value, Money):
42+
return ''
43+
4144
try:
4245
currency = currency if not pd.isna(currency) and currency_exists(currency, locale) else ''
4346

44-
return format_currency(value, currency, locale=locale) if not pd.isna(value) and isinstance(value, Money) else ''
47+
return format_currency(value, currency, locale=locale)
4548
except Exception: # pylint: disable=broad-exception-caught
4649
# fallback e.g. if system locale is None/not set, or currency does not exist
47-
return f"{value:.2f}" if isinstance(value, Money) else ''
50+
return f"{value:.2f}"
4851

4952

5053
def enum_types_to_name(enum_list: List[Any]) -> List[Any]:

tests/test_helper.py

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
('', None, 'EUR', 'en_US'),
3838
('', 9, 'EUR', 'fr_FR'),
3939
('', object(), 'EUR', 'fr_FR'),
40+
('', float('nan'), 'EUR', None),
4041
])
4142
def test_format_money(expected: str, money: Money, currency: str, locale_value: str) -> None:
4243
assert format_money(money, currency, locale_value) == expected

0 commit comments

Comments
 (0)