Skip to content

Commit 77ac3e5

Browse files
jbrockmendelpeterpanmj
authored andcommitted
nat division by timedelta (pandas-dev#17955)
1 parent 4070564 commit 77ac3e5

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

doc/source/whatsnew/v0.22.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Backwards incompatible API changes
4040
Other API Changes
4141
^^^^^^^^^^^^^^^^^
4242

43+
- ``NaT`` division with :class:`datetime.timedelta` will now return ``NaN`` instead of raising (:issue:`17876`)
4344
- :class:`Timestamp` will no longer silently ignore unused or invalid `tz` or `tzinfo` arguments (:issue:`17690`)
4445
-
4546
-

pandas/_libs/tslib.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1448,15 +1448,15 @@ _nat_scalar_rules[Py_GE] = False
14481448

14491449

14501450
cdef _nat_divide_op(self, other):
1451-
if (isinstance(other, Timedelta) or
1451+
if (PyDelta_Check(other) or
14521452
is_timedelta64_object(other) or other is NaT):
14531453
return np.nan
14541454
if is_integer_object(other) or is_float_object(other):
14551455
return NaT
14561456
return NotImplemented
14571457

14581458
cdef _nat_rdivide_op(self, other):
1459-
if isinstance(other, Timedelta):
1459+
if PyDelta_Check(other):
14601460
return np.nan
14611461
return NotImplemented
14621462

pandas/tests/scalar/test_nat.py

+2
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ def test_nat_arithmetic():
248248
assert left + right is NaT
249249
assert right - left is NaT
250250
assert left - right is NaT
251+
assert np.isnan(left / right)
252+
assert np.isnan(right / left)
251253

252254
# GH 11718
253255
t_utc = Timestamp('2014-01-01', tz='UTC')

0 commit comments

Comments
 (0)