From 3c1a114621f73a15b8e821e5b2a91a8a1fe58a2e Mon Sep 17 00:00:00 2001 From: Tianxiang Zhan <55232071+ztxtech@users.noreply.github.com> Date: Sun, 17 Sep 2023 19:33:09 +0800 Subject: [PATCH] fix nan and inf problems (#66) --- fitlog/fastlog/logger.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fitlog/fastlog/logger.py b/fitlog/fastlog/logger.py index cfd17e2..290afef 100644 --- a/fitlog/fastlog/logger.py +++ b/fitlog/fastlog/logger.py @@ -746,7 +746,7 @@ def _parse_value(value: Union[int, str, float, dict], name: str, parent_name: st elif isinstance(value, np.integer): value = int(value) elif isinstance(value, np.floating): - value = float(value) + value = float(value) if not(math.isnan(value) and math.isinf(value)) else str(value) else: value = str(value) # 直接专为str类型 assert name is not None, f"When value is `{type(value)}`, you must pass a name." @@ -796,7 +796,7 @@ def _check_dict_value(_dict: dict, prefix: str = ''): elif isinstance(value, (np.integer, int)): _dict[key] = int(value) elif isinstance(value, (np.floating, float)): - _dict[key] = float(value) + _dict[key] = float(value) if not (math.isnan(value) and math.isinf(value)) else str(value) else: _dict[key] = str(value)