Skip to content

nat division by timedelta #17955

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

Merged
merged 6 commits into from
Oct 28, 2017
Merged
Show file tree
Hide file tree
Changes from all 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.22.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Backwards incompatible API changes
Other API Changes
^^^^^^^^^^^^^^^^^

- ``NaT`` division with :class:`datetime.timedelta` will now return ``NaN`` instead of raising (:issue:`17876`)
- :class:`Timestamp` will no longer silently ignore unused or invalid `tz` or `tzinfo` arguments (:issue:`17690`)
-
-
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1448,15 +1448,15 @@ _nat_scalar_rules[Py_GE] = False


cdef _nat_divide_op(self, other):
if (isinstance(other, Timedelta) or
if (PyDelta_Check(other) or
is_timedelta64_object(other) or other is NaT):
return np.nan
if is_integer_object(other) or is_float_object(other):
return NaT
return NotImplemented

cdef _nat_rdivide_op(self, other):
if isinstance(other, Timedelta):
if PyDelta_Check(other):
return np.nan
return NotImplemented

Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/scalar/test_nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ def test_nat_arithmetic():
assert left + right is NaT
assert right - left is NaT
assert left - right is NaT
assert np.isnan(left / right)
assert np.isnan(right / left)

# GH 11718
t_utc = Timestamp('2014-01-01', tz='UTC')
Expand Down