Skip to content

Fix Issue #21336: Defeault behavior for resolution property in Timestamps #21365

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 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.23.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ Other

- Tab completion on :class:`Index` in IPython no longer outputs deprecation warnings (:issue:`21125`)
- Bug preventing pandas from being importable with -OO optimization (:issue:`21071`)
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this already in the **Other Fixes** section.

- Timestamp resolution returns a :class:`Timedelta` rather than a normal `timedelta` object (:issue:`21336`)
Copy link
Member

Choose a reason for hiding this comment

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

I think the main point of the issue was that before the stated resolution was 1 microsecond while in actuality its 1 nanosecond (but we can't use timedelta to express that because it doesn't support nanoseconds)

Copy link
Author

Choose a reason for hiding this comment

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

Resolved in commit c53f2c2

7 changes: 7 additions & 0 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,19 @@ cdef class _Timestamp(datetime):
def asm8(self):
return np.datetime64(self.value, 'ns')

@property
def resolution(self):
""" Return resolution in a native pandas format. """
# GH 21336
return Timedelta(nanoseconds=1)

def timestamp(self):
"""Return POSIX timestamp as float."""
# py27 compat, see GH#17329
return round(self.value / 1e9, 6)



# ----------------------------------------------------------------------

# Python front end to C extension type _Timestamp
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/scalar/timestamp/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ def test_woy_boundary(self):
2005, 1, 1), (2005, 1, 2)]])
assert (result == [52, 52, 53, 53]).all()

def test_resolution(self):
# GH 21336
dt = Timestamp('2100-01-01 00:00:00')
assert dt.resolution == Timedelta(nanoseconds=1)


class TestTimestampConstructors(object):

Expand Down