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

Refactor fill time periods function #25

Merged
merged 3 commits into from
Aug 14, 2024
Merged

Conversation

Sukh-P
Copy link
Member

@Sukh-P Sukh-P commented Aug 13, 2024

Pull Request

Description

Small refactor of fill_time_periods to remove using iterrows() to hopefully make it more efficient

How Has This Been Tested?

A unit test already existed for this which is great so just checked that still passes

@Sukh-P Sukh-P marked this pull request as ready for review August 13, 2024 16:31
@Sukh-P Sukh-P requested a review from dfulu August 13, 2024 16:31
Copy link
Member

@dfulu dfulu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use:

 start_dts = pd.to_datetime(time_periods["start_dt"]).ceil(freq)
 end_dts = pd.to_datetime(time_periods['end_dt'])

?

@Sukh-P
Copy link
Member Author

Sukh-P commented Aug 14, 2024

Could we use:

 start_dts = pd.to_datetime(time_periods["start_dt"]).ceil(freq)
 end_dts = pd.to_datetime(time_periods['end_dt'])

?

So that won't work for the start_dts but yeah that's a nicer way to do the end_dts, will change that now

@dfulu
Copy link
Member

dfulu commented Aug 14, 2024

So that won't work for the start_dts but yeah that's a nicer way to do the end_dts, will change that now

Oh okay, why won't it work for the start_dts? I ran:

pd.to_datetime(["2020-01-01 11:22", "2020-01-01 11:55",]).ceil(pd.Timedelta("1h"))
>> DatetimeIndex(['2020-01-01 12:00:00', '2020-01-01 12:00:00'], dtype='datetime64[ns]', freq=None)

Am I missing something?

@Sukh-P
Copy link
Member Author

Sukh-P commented Aug 14, 2024

I was missing a .values! Works now

@dfulu
Copy link
Member

dfulu commented Aug 14, 2024

I was missing a .values! Works now

Cool! Nice work. Sorry to nitpick but to keep it cleaner can we add .values to both, otherwise it raises the question of why only have it for one. Right now I think start_dt is a pd.DatetimeIndex but end_dt is a pd.Series

@Sukh-P Sukh-P requested a review from dfulu August 14, 2024 10:49
@Sukh-P Sukh-P merged commit b309d87 into main Aug 14, 2024
3 checks passed
@Sukh-P Sukh-P deleted the refactor-fill-time-periods branch August 14, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants