Skip to content

Commit cadd955

Browse files
committed
Override default resolution property from date-time object (with unit test)
1 parent 0c65c57 commit cadd955

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,19 @@ cdef class _Timestamp(datetime):
400400
def asm8(self):
401401
return np.datetime64(self.value, 'ns')
402402

403+
@property
404+
def resolution(self):
405+
""" Return resolution in a native pandas format. """
406+
# GH 21336
407+
return Timedelta(nanoseconds=1)
408+
403409
def timestamp(self):
404410
"""Return POSIX timestamp as float."""
405411
# py27 compat, see GH#17329
406412
return round(self.value / 1e9, 6)
407413

408414

415+
409416
# ----------------------------------------------------------------------
410417

411418
# Python front end to C extension type _Timestamp

pandas/tests/scalar/timestamp/test_timestamp.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ def test_woy_boundary(self):
172172
2005, 1, 1), (2005, 1, 2)]])
173173
assert (result == [52, 52, 53, 53]).all()
174174

175+
def test_resolution(self):
176+
# GH 21336
177+
dt = Timestamp('2100-01-01 00:00:00')
178+
assert dt.resolution == Timedelta(nanoseconds=1)
179+
175180

176181
class TestTimestampConstructors(object):
177182

0 commit comments

Comments
 (0)