Skip to content

Commit 8281941

Browse files
abkfenrisCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 1f583ac commit 8281941

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pipeline/s3_timeseries/pipeline.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,16 @@ def monthly_ds(
200200
)
201201
df = df.groupby(df.columns, axis=1).first()
202202

203-
df = clean_up_dtypes_and_nas(df, na_values="NAN")
203+
# Avoid attempting to convert the time column to numeric inside
204+
# clean_up_dtypes_and_nas, which causes unnecessary exceptions.
205+
if "time" in df.columns:
206+
time_col = df["time"]
207+
df_wo_time = df.drop(columns=["time"])
208+
df_wo_time = clean_up_dtypes_and_nas(df_wo_time, na_values="NAN")
209+
df_wo_time["time"] = time_col
210+
df = df_wo_time
211+
else:
212+
df = clean_up_dtypes_and_nas(df, na_values="NAN")
204213
daily_dfs.append(df)
205214

206215
df = pd.concat(daily_dfs, ignore_index=True)
@@ -382,7 +391,7 @@ def clean_up_dtypes_and_nas(
382391
for c in df.columns:
383392
try:
384393
df[c] = pd.to_numeric(df[c])
385-
except Exception as e:
394+
except (ValueError, TypeError) as e:
386395
print(f"Unable to convert column {c}: {e}")
387396

388397
return df

0 commit comments

Comments
 (0)