Skip to content

Commit

Permalink
Handle ValueError in date parsing to improve robustness of set_vcs_vi…
Browse files Browse the repository at this point in the history
…ntage_year function (#90)
  • Loading branch information
andersy005 authored Nov 21, 2024
1 parent 9dd0602 commit d6e29e2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion offsets_db_data/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ def set_vcs_vintage_year(df: pd.DataFrame, *, date_column: str) -> pd.DataFrame:
DataFrame with a new 'vintage' column, containing the vintage year of each transaction.
"""

df[date_column] = pd.to_datetime(df[date_column], format='%d/%m/%Y', utc=True)
try:
df[date_column] = pd.to_datetime(df[date_column], format='%d/%m/%Y', utc=True)
except ValueError:
df[date_column] = pd.to_datetime(df[date_column], utc=True)
df['vintage'] = df[date_column].dt.year
return df

Expand Down

0 comments on commit d6e29e2

Please sign in to comment.