-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: Support timespec argument in Timestamp.isoformat() (#26131) #38550
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 all commits
233a63a
f8b0c4b
4334132
972ce2b
1a508aa
575c283
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 |
---|---|---|
|
@@ -609,8 +609,8 @@ cdef class _Timestamp(ABCTimestamp): | |
# ----------------------------------------------------------------- | ||
# Rendering Methods | ||
|
||
def isoformat(self, sep: str = "T") -> str: | ||
base = super(_Timestamp, self).isoformat(sep=sep) | ||
def isoformat(self, sep: str = "T", timespec: str = "auto") -> str: | ||
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. is 'auto' the typical name for this? |
||
base = super(_Timestamp, self).isoformat(sep=sep, timespec=timespec) | ||
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 add a doc-string here |
||
if self.nanosecond == 0: | ||
return base | ||
|
||
|
@@ -619,7 +619,7 @@ cdef class _Timestamp(ABCTimestamp): | |
else: | ||
base1, base2 = base, "" | ||
|
||
if self.microsecond != 0: | ||
if self.microsecond != 0 and timespec in ("auto", "microseconds"): | ||
base1 += f"{self.nanosecond:03d}" | ||
else: | ||
base1 += f".{self.nanosecond:09d}" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from pandas import Timestamp | ||
|
||
|
||
def test_isoformat(): | ||
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 locate with with other formatting tests 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 suggest a more specific location that would be better? I looked, but couldn't find an obvious place where other formatting tests are located. |
||
ts = Timestamp( | ||
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. Does this handle a nanosecond argument? |
||
year=2019, month=5, day=18, hour=15, minute=17, second=8, microsecond=132263 | ||
) | ||
assert ts.isoformat() == "2019-05-18T15:17:08.132263" | ||
assert ts.isoformat(timespec="seconds") == "2019-05-18T15:17:08" |
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 issue is tagged as enhancement so this probably should be moved there
Also I would expect this to target v1.3 not v1.2
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.
yeah pls move this to 1.3 under other enhancements