Skip to content

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

Closed
wants to merge 6 commits into from

Conversation

marius-mather
Copy link

I have just tried to support the same behaviour as datetime.datetime(), without adding the additional "nanoseconds" option, but this could be handled as well.

Copy link
Member

@arw2019 arw2019 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

Looks good, some comments

@@ -607,6 +607,7 @@ Datetimelike
- Bug in :meth:`Series.isin` with ``datetime64[ns]`` dtype and :meth:`.DatetimeIndex.isin` failing to consider timezone-aware and timezone-naive datetimes as always different (:issue:`35728`)
- Bug in :meth:`Series.isin` with ``PeriodDtype`` dtype and :meth:`PeriodIndex.isin` failing to consider arguments with different ``PeriodDtype`` as always different (:issue:`37528`)
- Bug in :class:`Period` constructor now correctly handles nanoseconds in the ``value`` argument (:issue:`34621` and :issue:`17053`)
- Bug in :meth:`Timestamp.isoformat`, now handles the ``timespec`` argument from the base :class:``datetime`` class (:issue:`26131`)
Copy link
Member

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

Copy link
Contributor

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



def test_isoformat():
ts = Timestamp(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this handle a nanosecond argument?

@jreback jreback added the Datetime Datetime data dtype label Dec 21, 2020
@jreback jreback added this to the 1.3 milestone Dec 21, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will also want to add this arg for a datetime index as well. (can be done as a followup or even better in this PR)

@@ -607,6 +607,7 @@ Datetimelike
- Bug in :meth:`Series.isin` with ``datetime64[ns]`` dtype and :meth:`.DatetimeIndex.isin` failing to consider timezone-aware and timezone-naive datetimes as always different (:issue:`35728`)
- Bug in :meth:`Series.isin` with ``PeriodDtype`` dtype and :meth:`PeriodIndex.isin` failing to consider arguments with different ``PeriodDtype`` as always different (:issue:`37528`)
- Bug in :class:`Period` constructor now correctly handles nanoseconds in the ``value`` argument (:issue:`34621` and :issue:`17053`)
- Bug in :meth:`Timestamp.isoformat`, now handles the ``timespec`` argument from the base :class:``datetime`` class (:issue:`26131`)
Copy link
Contributor

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

def isoformat(self, sep: str = "T") -> str:
base = super(_Timestamp, self).isoformat(sep=sep)
def isoformat(self, sep: str = "T", timespec: str = "auto") -> str:
base = super(_Timestamp, self).isoformat(sep=sep, timespec=timespec)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add a doc-string here

@@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is 'auto' the typical name for this?

from pandas import Timestamp


def test_isoformat():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you locate with with other formatting tests

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@jreback jreback removed this from the 1.3 milestone Dec 21, 2020
@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Jan 21, 2021
@mroeschke
Copy link
Member

Thanks for the PR, but going to close due the lack of activity. Let us know if you'd like to continue working on this.

@swt2c
Copy link
Contributor

swt2c commented Nov 11, 2021

I'm planning to take over this PR as the original author seems to have lost time/interest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pd.Timestamp.isoformat does not implement keyword timespec
5 participants