From d9ae2009efbe4617277c779d8f474927efe89c48 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 23 Oct 2017 08:09:46 -0700 Subject: [PATCH 1/4] nat division by timedelta --- pandas/_libs/tslib.pyx | 4 ++-- pandas/tests/scalar/test_nat.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslib.pyx b/pandas/_libs/tslib.pyx index a0aae6a5de707..c0a36e9f52467 100644 --- a/pandas/_libs/tslib.pyx +++ b/pandas/_libs/tslib.pyx @@ -1428,7 +1428,7 @@ _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): @@ -1436,7 +1436,7 @@ cdef _nat_divide_op(self, other): return NotImplemented cdef _nat_rdivide_op(self, other): - if isinstance(other, Timedelta): + if PyDelta_Check(other): return np.nan return NotImplemented diff --git a/pandas/tests/scalar/test_nat.py b/pandas/tests/scalar/test_nat.py index 135e4c544de41..71bce79f05b12 100644 --- a/pandas/tests/scalar/test_nat.py +++ b/pandas/tests/scalar/test_nat.py @@ -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') From ac19de61e3487e61615bcb8fd08d3d17b87a4225 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 23 Oct 2017 08:27:10 -0700 Subject: [PATCH 2/4] whatsnew note --- doc/source/whatsnew/v0.21.0.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 18f8858748df5..5ebfa2183c84a 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -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`) .. _whatsnew_0210.deprecations: From 76017cc02d1bcf14c39da4dc38d42367523cf683 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 23 Oct 2017 11:58:15 -0700 Subject: [PATCH 3/4] double ticks around NaN --- doc/source/whatsnew/v0.21.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 5ebfa2183c84a..1e715215f0315 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -830,7 +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`) +- ``NaT`` division with :class:`datetime.timedelta` will now return ``NaN`` instead of raising (:issue:`17876`) .. _whatsnew_0210.deprecations: From 9d627a2d6ce90098f70c2118142dc709a4b61c9b Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 27 Oct 2017 09:05:39 -0700 Subject: [PATCH 4/4] move whatsnew note to 0.22.0 --- doc/source/whatsnew/v0.21.0.txt | 1 - doc/source/whatsnew/v0.22.0.txt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index bb10654a1def7..4c460eeb85b82 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -902,7 +902,6 @@ 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`) .. _whatsnew_0210.deprecations: diff --git a/doc/source/whatsnew/v0.22.0.txt b/doc/source/whatsnew/v0.22.0.txt index 53b052a955b45..8fb6718c11144 100644 --- a/doc/source/whatsnew/v0.22.0.txt +++ b/doc/source/whatsnew/v0.22.0.txt @@ -40,7 +40,7 @@ Backwards incompatible API changes Other API Changes ^^^^^^^^^^^^^^^^^ -- +- ``NaT`` division with :class:`datetime.timedelta` will now return ``NaN`` instead of raising (:issue:`17876`) - -