Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix check_group_daterange function in preprocessor.py #568

Merged
merged 3 commits into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,17 @@ def check_group_daterange(self, group_df: pd.DataFrame, log=_log) -> pd.DataFram
if not hasattr(group_df, 'start_time') or not hasattr(group_df, 'end_time'):
raise AttributeError('Data catalog is missing attributes `start_time` and/or `end_time`')
try:
if not isinstance(group_df['start_time'].values[0], datetime.date):
# convert int to date type
date_format = ''
date_digits = math.floor(math.log10(group_df['start_time'].values[0]))+1
match date_digits:
case 8:
date_format = '%Y%m%d'
case 14:
date_format = '%Y%m%d%H%M%S'
group_df['start_time'] = pd.to_datetime(group_df['start_time'].values[0], format=date_format)
group_df['end_time'] = pd.to_datetime(group_df['end_time'].values[0], format=date_format)
# method throws ValueError if ranges aren't contiguous
dates_df = group_df.loc[:, ['start_time', 'end_time']]
date_range_vals = []
Expand Down
Loading