-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
ENH: Add additional options to nonexistent in tz_localize #24493
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9468f18
ENH: Add other shift options
a796262
Add timestamp tests
635804b
Change NaT docstring
515251f
Add DatetimeIndex tests
43430b9
lint and add to generic.py
70fe768
Change documentation and add more tests
c7bba62
Use PyDelta_Check
0f79166
Lint imports
b2a3c72
Add docstring examples
5fd9110
Merge remote-tracking branch 'upstream/master' into nonexistent_options
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,13 +233,17 @@ class TimelikeOps(object): | |
|
||
.. versionadded:: 0.24.0 | ||
|
||
nonexistent : 'shift', 'NaT', default 'raise' | ||
nonexistent : 'shift_forward', 'shift_backward, 'NaT', timedelta, | ||
default 'raise' | ||
A nonexistent time does not exist in a particular timezone | ||
where clocks moved forward due to DST. | ||
|
||
- 'shift' will shift the nonexistent time forward to the closest | ||
existing time | ||
- 'shift_forward' will shift the nonexistent time forward to the | ||
closest existing time | ||
- 'shift_backward' will shift the nonexistent time backward to the | ||
closest existing time | ||
- 'NaT' will return NaT where there are nonexistent times | ||
- timedelta objects will shift nonexistent times by the timedelta | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC cython doesn't play nicely with docstring templating; might be worth opening an issue over there to request it |
||
- 'raise' will raise an NonExistentTimeError if there are | ||
nonexistent times | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a practical use of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the original enhancement request #24466 (comment), there was no way to shift backwards, moreover by a specified amount. I can see how it would be valuable to shift nonexistent times forward or backwards by a specified amount instead of the closest time. (e.g. I want times on the half hours, so be able to shift times to 1:30 or 3:30 and not just 1:59 or 3:00)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this duplicating shift_backwards though? this seems unecessarily complex to do anything more that doing a snap, eg. to a valid time (forward or backwards). shifting is an independent operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it didn't add too much more complexity to the code, but here was @sdementen use case:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see how in principle how it's very similar to
shift_forward
/shift_backwards
then adding an offset, but it can be easier determining how you want to shift from a nonexistent time compared to a nonexistent time that has been snapped to 1:59 or 3:00.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sdementen care to chime in on thoughts?