Skip to content

Commit

Permalink
fix: add_age
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBernstorff committed Nov 24, 2023
1 parent 6038e59 commit cd70370
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/timeseriesflattener/flattened_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,11 +874,11 @@ def add_age(
try:
date_of_birth_df[date_of_birth_col_name] = pd.to_datetime(
date_of_birth_df[date_of_birth_col_name],
format="%Y-%m-%d",
)

except ValueError as e:
raise ValueError(
f"Conversion of {date_of_birth_col_name} to datetime failed, doesn't match format %Y-%m-%d. Recommend converting to datetime before adding.",
f"Conversion of {date_of_birth_col_name} to datetime failed. Recommend converting to datetime before adding.",
) from e

output_age_col_name = f"{output_prefix}_age_in_years"
Expand All @@ -898,7 +898,8 @@ def add_age(

self._df[output_age_col_name] = (
(
self._df[self.timestamp_col_name] - self._df[tmp_date_of_birth_col_name]
pd.to_datetime(self._df[self.timestamp_col_name])
- self._df[tmp_date_of_birth_col_name]
).dt.days
/ (365.25)
).round(2)
Expand Down

0 comments on commit cd70370

Please sign in to comment.