Skip to content

Commit 9e77191

Browse files
committed
added a test for Timestamp
1 parent 52c897a commit 9e77191

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pandas/tseries/tests/test_timeseries.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4858,6 +4858,15 @@ def test_is_leap_year(self):
48584858
self.assertFalse(pd.NaT.is_leap_year)
48594859
self.assertIsInstance(pd.NaT.is_leap_year, bool)
48604860

4861+
def test_round_nat(self):
4862+
# GH14940
4863+
ts = Timestamp('nat')
4864+
print(dir(ts))
4865+
for method in ["round", "floor", "ceil"]:
4866+
round_method = getattr(ts, method)
4867+
for freq in ["s", "5s", "min", "5min", "h", "5h"]:
4868+
self.assertIs(round_method(freq), ts)
4869+
48614870

48624871
class TestSlicing(tm.TestCase):
48634872
def test_slice_year(self):

pandas/tslib.pyx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,12 @@ def _make_nan_func(func_name):
885885
f.__name__ = func_name
886886
return f
887887

888+
889+
# GH14940
890+
_round_methods = ['round', 'floor', 'ceil']
891+
888892
_nat_methods = ['date', 'now', 'replace', 'to_pydatetime', 'today']
893+
_nat_methods.extend(_round_methods)
889894

890895
_nan_methods = ['weekday', 'isoweekday', 'total_seconds']
891896

@@ -895,7 +900,7 @@ _implemented_methods.extend(_nan_methods)
895900

896901
for _method_name in _nat_methods:
897902
# not all methods exist in all versions of Python
898-
if hasattr(NaTType, _method_name):
903+
if hasattr(NaTType, _method_name) or _method_name in _round_methods:
899904
setattr(NaTType, _method_name, _make_nat_func(_method_name))
900905

901906
for _method_name in _nan_methods:

0 commit comments

Comments
 (0)