Skip to content

Commit

Permalink
Improve datetime conversion handling by adding fallback for ValueErro…
Browse files Browse the repository at this point in the history
…r in `convert_to_datetime` function (#94)
  • Loading branch information
andersy005 authored Dec 3, 2024
1 parent 3d5b43b commit 85f377a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions offsets_db_data/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ def convert_to_datetime(
"""

for column in columns:
if column in df.columns:
df[column] = pd.to_datetime(df[column], utc=utc, **kwargs).dt.normalize()
else:
if column not in df.columns:
raise KeyError(f"The column '{column}' is missing.")
try:
df[column] = pd.to_datetime(df[column], utc=utc, **kwargs).dt.normalize()
except ValueError:
df[column] = pd.to_datetime(df[column], utc=utc).dt.normalize()
return df


Expand Down

0 comments on commit 85f377a

Please sign in to comment.