-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Support timespec argument in Timestamp.isoformat() #44397
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
Changes from 3 commits
01ea8c4
49abcfe
56ae9bd
8e59575
c29f3ca
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import pytest | ||
|
||
from pandas import Timestamp | ||
|
||
ts_no_ns = Timestamp( | ||
year=2019, | ||
month=5, | ||
day=18, | ||
hour=15, | ||
minute=17, | ||
second=8, | ||
microsecond=132263, | ||
) | ||
ts_ns = Timestamp( | ||
year=2019, | ||
month=5, | ||
day=18, | ||
hour=15, | ||
minute=17, | ||
second=8, | ||
microsecond=132263, | ||
nanosecond=123, | ||
) | ||
ts_ns_tz = Timestamp( | ||
year=2019, | ||
month=5, | ||
day=18, | ||
hour=15, | ||
minute=17, | ||
second=8, | ||
microsecond=132263, | ||
nanosecond=123, | ||
tz="UTC", | ||
) | ||
ts_no_us = Timestamp( | ||
year=2019, | ||
month=5, | ||
day=18, | ||
hour=15, | ||
minute=17, | ||
second=8, | ||
microsecond=0, | ||
nanosecond=123, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"ts, timespec, expected_iso", | ||
[ | ||
(ts_no_ns, "auto", "2019-05-18T15:17:08.132263"), | ||
(ts_no_ns, "seconds", "2019-05-18T15:17:08"), | ||
(ts_no_ns, "nanoseconds", "2019-05-18T15:17:08.132263000"), | ||
(ts_ns, "auto", "2019-05-18T15:17:08.132263123"), | ||
(ts_ns, "hours", "2019-05-18T15"), | ||
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. can you also run on NaT 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. Not sure it made sense to run the same tests on NaT(?) but I did add a test to the NaT tests to check that it at least accepts the |
||
(ts_ns, "minutes", "2019-05-18T15:17"), | ||
(ts_ns, "seconds", "2019-05-18T15:17:08"), | ||
(ts_ns, "milliseconds", "2019-05-18T15:17:08.132"), | ||
(ts_ns, "microseconds", "2019-05-18T15:17:08.132263"), | ||
(ts_ns, "nanoseconds", "2019-05-18T15:17:08.132263123"), | ||
(ts_ns_tz, "auto", "2019-05-18T15:17:08.132263123+00:00"), | ||
(ts_ns_tz, "hours", "2019-05-18T15+00:00"), | ||
(ts_ns_tz, "minutes", "2019-05-18T15:17+00:00"), | ||
(ts_ns_tz, "seconds", "2019-05-18T15:17:08+00:00"), | ||
(ts_ns_tz, "milliseconds", "2019-05-18T15:17:08.132+00:00"), | ||
(ts_ns_tz, "microseconds", "2019-05-18T15:17:08.132263+00:00"), | ||
(ts_ns_tz, "nanoseconds", "2019-05-18T15:17:08.132263123+00:00"), | ||
(ts_no_us, "auto", "2019-05-18T15:17:08.000000123"), | ||
], | ||
) | ||
def test_isoformat(ts, timespec, expected_iso): | ||
assert ts.isoformat(timespec=timespec) == expected_iso |
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.
this example should be for NaT (to be honest dont' need it here though)
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.
The problem I ran into - there was a test failure because the docstrings differed between NaT and Timestamp, so that's why I copied the docstring into NaT. Do you have any advice about that?
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.
right we have tests that confirm this, but since we are not explicitly making these differnt you can change the test
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.
OK, so I ended up reverting the docstring change to NaT and updated the test to ignore the docstring changes with Timestamp.