Be compatible with numpy 1.18
authorDebian Science Team <debian-science-maintainers@lists.alioth.debian.org>
Thu, 7 May 2020 10:57:06 +0000 (11:57 +0100)
committerRebecca N. Palmer <rebecca_palmer@zoho.com>
Thu, 7 May 2020 10:57:06 +0000 (11:57 +0100)
Fix NaT sort order
Don't assume isinf/isnan fail on datetimes

Origin: upstream f85502531806df4f3c0233edffe9460f3ee26031 + 0c0adfbc291fc1b1e9afad592f5275e783ffd0b0
Author: jbrockmendel, Rebecca N. Palmer <rebecca_palmer@zoho.com>
Bug-Debian: https://bugs.debian.org/958531

Gbp-Pq: Name numpy118_compat.patch

pandas/__init__.py
pandas/core/indexes/datetimelike.py
pandas/tests/api/test_api.py
pandas/tests/indexes/test_numpy_compat.py

index 0354797d5c6717bee180da914c1f946df9192b14..bd4d97265ce7051e1348a3777b85ed6a3c80a450 100644 (file)
@@ -24,6 +24,7 @@ from pandas.compat.numpy import (
     _np_version_under1p15,
     _np_version_under1p16,
     _np_version_under1p17,
+    _np_version_under1p18,
 )
 
 try:
index 731ab9c4163453c3e179070a128e1d38c44ae4cc..4cbd90f659e482d24cea2fae047920fad8d8e2b0 100644 (file)
@@ -262,7 +262,10 @@ class DatetimeIndexOpsMixin(ExtensionOpsMixin):
             sorted_index = self.take(_as)
             return sorted_index, _as
         else:
-            sorted_values = np.sort(self._ndarray_values)
+            # NB: using asi8 instead of _ndarray_values matters in numpy 1.18
+            #  because the treatment of NaT has been changed to put NaT last
+            #  instead of first.
+            sorted_values = np.sort(self.asi8)
             attribs = self._get_attributes_dict()
             freq = attribs["freq"]
 
index 941105dd679f86646cb6111204ac83b825fb0fcd..b3737642e2cbf45f2ebd2580b13501b26b95b5ea 100644 (file)
@@ -187,6 +187,7 @@ class TestPDApi(Base):
         "_np_version_under1p15",
         "_np_version_under1p16",
         "_np_version_under1p17",
+        "_np_version_under1p18",
         "_tslib",
         "_typing",
 # not in Debian        "_version",
index 1d56a9c1cd52a295ce9f46aaaf2ecabe4ca1e510..8ba2f587a41ff47b9b6c79605aaa9db541f1ecdb 100644 (file)
@@ -6,9 +6,11 @@ from pandas import (
     Float64Index,
     Index,
     Int64Index,
+    PeriodIndex,
     TimedeltaIndex,
     UInt64Index,
     _np_version_under1p17,
+    _np_version_under1p18,
 )
 from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
 from pandas.util import testing as tm
@@ -80,18 +82,22 @@ def test_numpy_ufuncs_other(indices, func):
     idx = indices
     if isinstance(idx, (DatetimeIndex, TimedeltaIndex)):
 
-        # ok under numpy >= 1.17
-        if not _np_version_under1p17 and func in [np.isfinite]:
+        if not _np_version_under1p18 and func in [np.isfinite, np.isinf, np.isnan]:
+            # numpy 1.18(dev) changed isinf and isnan to not raise on dt64/tfd64
+            result = func(idx)
+            assert isinstance(result, np.ndarray)
+
+        elif not _np_version_under1p17 and func in [np.isfinite]:
+            # ok under numpy >= 1.17
             # Results in bool array
             result = func(idx)
             assert isinstance(result, np.ndarray)
-            assert not isinstance(result, Index)
         else:
             # raise TypeError or ValueError (PeriodIndex)
             with pytest.raises(Exception):
                 func(idx)
 
-    elif isinstance(idx, DatetimeIndexOpsMixin):
+    elif isinstance(idx, PeriodIndex):
         # raise TypeError or ValueError (PeriodIndex)
         with pytest.raises(Exception):
             func(idx)