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 3 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.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ Other API Changes
- Restricted DateOffset keyword arguments. Previously, ``DateOffset`` subclasses allowed arbitrary keyword arguments which could lead to unexpected behavior. Now, only valid arguments will be accepted. (:issue:`17176`).
- Pandas no longer registers matplotlib converters on import. The converters
will be registered and used when the first plot is draw (:issue:`17710`)
- ``NaT`` division with :class:`datetime.timedelta` will now return ``NaN`` instead of raising (:issue:`17876`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so will move to 0.21.1 when its available

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move to 0.22.0 other api changes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Out of curiosity, why 0.22.0 instead of 0.21.1?


.. _whatsnew_0210.deprecations:

Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1428,15 +1428,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 @@ -247,6 +247,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