-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: zero-pad shorter years in Timestamp.isoformat
#52220
Changes from 3 commits
eb651c2
1ccf530
7450c13
e5f7b48
ab87865
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -595,19 +595,16 @@ def test_out_of_bounds_string_consistency(self, arg): | |
# GH 15829 | ||
msg = "|".join( | ||
[ | ||
"Cannot cast 1-01-01 00:00:00 to unit='ns' without overflow", | ||
"Out of bounds nanosecond timestamp: 1-01-01 00:00:00", | ||
"Cannot cast 0001-01-01 00:00:00 to unit='ns' without overflow", | ||
"Out of bounds nanosecond timestamp: 0001-01-01 00:00:00", | ||
] | ||
) | ||
with pytest.raises(OutOfBoundsDatetime, match=msg): | ||
Timestamp(arg).as_unit("ns") | ||
|
||
if arg == "0001-01-01": | ||
# only the 4-digit year goes through ISO path which gets second reso | ||
# instead of ns reso | ||
ts = Timestamp(arg) | ||
assert ts.unit == "s" | ||
assert ts.year == ts.month == ts.day == 1 | ||
ts = Timestamp(arg) | ||
assert ts.unit == "s" | ||
assert ts.year == ts.month == ts.day == 1 | ||
Comment on lines
-611
to
+608
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. nice! and also a reminder that if we have an I'm having a look and when this was fixed 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. |
||
|
||
def test_min_valid(self): | ||
# Ensure that Timestamp.min is a valid Timestamp | ||
|
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.
To elaborate on my comment in the issue, my guess is that it used to be that different error messages were raised for the different input options in this test:
"001-01-01"
the Timestamp constructor assumed nanosecond precision and so would not allow the construction of a nanosecond Timestamp with year equal one, raising the"Out of bounds nanosecond timestamp: 0001-01-01 00:00:00"
message before one could try theas_unit
call. This necessitated the if-statement below, because it meant it was not possible to create a Timestamp object with"001-01-01"
(i.e. previously line 608) without raising an error, so one could not query itsunit
."0001-01-01"
a second precision Timestamp with year equal one was created, but when attempting to convert to nanosecond precision withas_unit
the"Cannot cast 0001-01-01 00:00:00 to unit='ns' without overflow"
message was raised.Now that the Timestamp constructor appears to assume second precision for
"001-01-01"
as well, the"Out of bounds nanosecond timestamp: 0001-01-01 00:00:00"
is no longer raised for either of the two test cases, so the matching condition can be simplified to be the"Cannot cast 0001-01-01 00:00:00 to unit='ns' without overflow"
message alone.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.
thanks, I removed the check for the
Out of bounds
message