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 DatetimeRange timestamp iteration #17

Merged
merged 2 commits into from
Nov 14, 2024
Merged

Conversation

lixiliu
Copy link
Collaborator

@lixiliu lixiliu commented Nov 12, 2024

Problem: DatetimeRange.iter_timestamps() does not return the correct time series when the starting timestamp is tz-aware and in a timezone with DST.

Currently the function produces the following at spring-forward:

                     timestamp
1656 2018-03-11 00:00:00-07:00
1657 2018-03-11 01:00:00-07:00
1658 2018-03-11 03:00:00-06:00
1659 2018-03-11 03:00:00-06:00

It needs to be:

                     timestamp
1656 2018-03-11 00:00:00-07:00
1657 2018-03-11 01:00:00-07:00
1658 2018-03-11 03:00:00-06:00
1659 2018-03-11 04:00:00-06:00

Solution: Advance timestamp in standard timezone (e.g., UTC) and convert back to input timezone before yielding.

Also fixed DatetimeRange.list_timestamps_from_dataframe() to return unique timestamps only. Do we need sort it?

Did not fix relevant pytests

@lixiliu lixiliu changed the title Fix DatetimeRange timestamp iterations Fix DatetimeRange timestamp iteration Nov 12, 2024
@@ -184,14 +185,22 @@ def is_time_zone_naive(self) -> bool:
return self.start.tzinfo is None

def list_timestamps_from_dataframe(self, df: pd.DataFrame) -> list[datetime]:
return df[self.time_column].to_list()
return df[self.time_column].drop_duplicates().to_list()
Copy link
Collaborator

Choose a reason for hiding this comment

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

It needs to be sorted. I did that in #16

@codecov-commenter
Copy link

codecov-commenter commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.24%. Comparing base (ac69a9e) to head (f8bc1f2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #17      +/-   ##
==========================================
+ Coverage   94.20%   94.24%   +0.03%     
==========================================
  Files          18       18              
  Lines         777      782       +5     
==========================================
+ Hits          732      737       +5     
  Misses         45       45              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@daniel-thom daniel-thom left a comment

Choose a reason for hiding this comment

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

Thanks

@daniel-thom daniel-thom merged commit 8e4a674 into main Nov 14, 2024
6 checks passed
@daniel-thom daniel-thom deleted the ll/fix_iter_timestamps branch November 14, 2024 00:28
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.

3 participants