Skip to content

Commit 52c897a

Browse files
committed
BUG: added maybe_mask_results to '_round' method
1 parent 5a0eb5a commit 52c897a

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

doc/source/whatsnew/v0.20.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,5 @@ Bug Fixes
366366

367367

368368
- Bug in ``pd.read_csv()`` for the C engine where ``usecols`` were being indexed incorrectly with ``parse_dates`` (:issue:`14792`)
369+
370+
- Bug in ``Series.dt.round`` inconsistent behaviour on NAT's with different arguments (:issue:`14940`)

pandas/tseries/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def _round(self, freq, rounder):
8484
values = _ensure_datetimelike_to_i8(self)
8585

8686
result = (unit * rounder(values / float(unit))).astype('i8')
87+
result = self._maybe_mask_results(result, fill_value=tslib.NaT)
8788
attribs = self._get_attributes_dict()
8889
if 'freq' in attribs:
8990
attribs['freq'] = None

pandas/tseries/tests/test_timeseries.py

+9
Original file line numberDiff line numberDiff line change
@@ -4441,6 +4441,15 @@ def test_nat_operations(self):
44414441
self.assertEqual(s.min(), exp)
44424442
self.assertEqual(s.max(), exp)
44434443

4444+
def test_round_nat(self):
4445+
# GH14940
4446+
s = Series([pd.NaT])
4447+
expected = Series(pd.NaT)
4448+
for method in ["round", "floor", "ceil"]:
4449+
round_method = getattr(s.dt, method)
4450+
for freq in ["s", "5s", "min", "5min", "h", "5h"]:
4451+
assert_series_equal(round_method(freq), expected)
4452+
44444453

44454454
class TestTimestamp(tm.TestCase):
44464455
def test_class_ops_pytz(self):

0 commit comments

Comments
 (0)