From 55566f5c3adad9e726d323bf3c7b47a158fc66fe Mon Sep 17 00:00:00 2001 From: Ryan Duecker Date: Sat, 1 Jun 2024 12:34:01 -0700 Subject: [PATCH] better errors for safe convert --- src/cheetahpy/local_opendata.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cheetahpy/local_opendata.py b/src/cheetahpy/local_opendata.py index 8e56bde..f3a6381 100644 --- a/src/cheetahpy/local_opendata.py +++ b/src/cheetahpy/local_opendata.py @@ -95,7 +95,12 @@ def _safe_convert(original_series:pd.Series, type_convert:type) -> pd.Series: new_series = original_series.astype(type_convert) return new_series except Exception as err: - print(f'{err}: cannot convert {type(original_series)} to type {type_convert}') + a_value = original_series.dropna().tolist() + if len(a_value) > 0: + a_value_type = type(a_value[0]) + else: + a_value_type = "UNKNOWN" + print(f'{err}: cannot convert {original_series.name} (of type: {a_value_type}) to type {type_convert}') return original_series @staticmethod