From b5a771f4815e8ba3ad34e4cf55a7a26c8861df76 Mon Sep 17 00:00:00 2001 From: RyanAugust Date: Sat, 23 Sep 2023 04:03:50 +0000 Subject: [PATCH] fix athlete summary bug --- cheetahpy/local_opendata.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/cheetahpy/local_opendata.py b/cheetahpy/local_opendata.py index 9ba8583..1a01188 100644 --- a/cheetahpy/local_opendata.py +++ b/cheetahpy/local_opendata.py @@ -33,19 +33,20 @@ def get_athlete_summary(self, athlete_id:str, make_float:bool = True): rides = json.loads(summary_json)['RIDES'] df = pd.json_normalize(rides) if make_float: - for col in df.columns.tolist(): - if 'METRIC' in col: - if isinstance(df[col].dropna().values[0], str): - df[col] = self._safe_convert(original_series=df[col], type_convert=float) - elif isinstance(df[col].dropna().values[0], list): - try: - decompression = self._safe_list_decompression(original_series=df[col], type_convert=float) - df = df.join(decompression) - del df[col] - except Exception as err: - print(f'{err}: {col}--fail') - else: - None + metric_cols = [] + [metric_cols.append(col) if 'METRIC' in col else None for col in df.columns.tolist()] + for col in metric_cols: + if isinstance(df[col].dropna().values[0], str): + df[col] = self._safe_convert(original_series=df[col], type_convert=float) + elif isinstance(df[col].dropna().values[0], list): + try: + decompression = self._safe_list_decompression(original_series=df[col], type_convert=float) + df = df.join(decompression) + del df[col] + except Exception as err: + print(f'{err}: {col}--fail') + else: + None return df def get_athlete_activity_files(self, athlete_id:str) -> list: