-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Period constructor raises instead of ignoring when passing a string with extra precision(pico, femto, etc.) #50417
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
jbrockmendel
merged 5 commits into
pandas-dev:main
from
lithomas1:test-period-zero-nanos
Jan 16, 2023
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
89a5b68
TST: Add test for Period construction from str with zero nanos
lithomas1 20b6b13
BUG: Period would raise a KeyError when given a string with extra pre…
lithomas1 773df4f
Merge branch 'main' into test-period-zero-nanos
lithomas1 1e67122
Update parsing.pyx
lithomas1 ee250e5
Merge branch 'main' into test-period-zero-nanos
lithomas1 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -386,7 +386,7 @@ cdef parse_datetime_string_with_reso( | |
&out_tzoffset, False | ||
) | ||
if not string_to_dts_failed: | ||
if dts.ps != 0 or out_local: | ||
if out_bestunit == NPY_DATETIMEUNIT.NPY_FR_ns or out_local: | ||
# TODO: the not-out_local case we could do without Timestamp; | ||
# avoid circular import | ||
from pandas import Timestamp | ||
|
@@ -395,6 +395,12 @@ cdef parse_datetime_string_with_reso( | |
parsed = datetime( | ||
dts.year, dts.month, dts.day, dts.hour, dts.min, dts.sec, dts.us | ||
) | ||
# Match Timestamp and drop picoseconds, femtoseconds, attoseconds | ||
# The new resolution will just be nano | ||
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. GH ref pointing back here? |
||
if out_bestunit in {NPY_DATETIMEUNIT.NPY_FR_ps, | ||
NPY_DATETIMEUNIT.NPY_FR_fs, | ||
NPY_DATETIMEUNIT.NPY_FR_as}: | ||
out_bestunit = NPY_DATETIMEUNIT.NPY_FR_ns | ||
reso = { | ||
NPY_DATETIMEUNIT.NPY_FR_Y: "year", | ||
NPY_DATETIMEUNIT.NPY_FR_M: "month", | ||
|
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
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.
makes sense. to be totally correct we might need to check for ps, fs, as?
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.
Good point. What should be the error message we raise, or should we silently ignore?
On 1.5.2, doing
pd.Period("1970/01/01 00:00:00.000000000111")
gives meTimestamp seems to ignore the extra precision, so maybe we should match that here?
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.
definitely better than the status quo. it might be reasonable to have Timestamp warn/raise instead of silently truncating, but thats out of scope.