Skip to content

Commit c819095

Browse files
Debian Science Teamrebecca-palmer
authored andcommitted
Be compatible with numpy 1.18
Fix NaT sort order Don't assume isinf/isnan fail on datetimes Origin: upstream f85502531806df4f3c0233edffe9460f3ee26031 + 0c0adfbc291fc1b1e9afad592f5275e783ffd0b0 Author: jbrockmendel, Rebecca N. Palmer <[email protected]> Bug-Debian: https://bugs.debian.org/958531 Gbp-Pq: Name numpy118_compat.patch
1 parent 70e5018 commit c819095

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

pandas/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
_np_version_under1p15,
2525
_np_version_under1p16,
2626
_np_version_under1p17,
27+
_np_version_under1p18,
2728
)
2829

2930
try:

pandas/core/indexes/datetimelike.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ def sort_values(self, return_indexer=False, ascending=True):
262262
sorted_index = self.take(_as)
263263
return sorted_index, _as
264264
else:
265-
sorted_values = np.sort(self._ndarray_values)
265+
# NB: using asi8 instead of _ndarray_values matters in numpy 1.18
266+
# because the treatment of NaT has been changed to put NaT last
267+
# instead of first.
268+
sorted_values = np.sort(self.asi8)
266269
attribs = self._get_attributes_dict()
267270
freq = attribs["freq"]
268271

pandas/tests/api/test_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class TestPDApi(Base):
187187
"_np_version_under1p15",
188188
"_np_version_under1p16",
189189
"_np_version_under1p17",
190+
"_np_version_under1p18",
190191
"_tslib",
191192
"_typing",
192193
# not in Debian "_version",

pandas/tests/indexes/test_numpy_compat.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
Float64Index,
77
Index,
88
Int64Index,
9+
PeriodIndex,
910
TimedeltaIndex,
1011
UInt64Index,
1112
_np_version_under1p17,
13+
_np_version_under1p18,
1214
)
1315
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
1416
from pandas.util import testing as tm
@@ -80,18 +82,22 @@ def test_numpy_ufuncs_other(indices, func):
8082
idx = indices
8183
if isinstance(idx, (DatetimeIndex, TimedeltaIndex)):
8284

83-
# ok under numpy >= 1.17
84-
if not _np_version_under1p17 and func in [np.isfinite]:
85+
if not _np_version_under1p18 and func in [np.isfinite, np.isinf, np.isnan]:
86+
# numpy 1.18(dev) changed isinf and isnan to not raise on dt64/tfd64
87+
result = func(idx)
88+
assert isinstance(result, np.ndarray)
89+
90+
elif not _np_version_under1p17 and func in [np.isfinite]:
91+
# ok under numpy >= 1.17
8592
# Results in bool array
8693
result = func(idx)
8794
assert isinstance(result, np.ndarray)
88-
assert not isinstance(result, Index)
8995
else:
9096
# raise TypeError or ValueError (PeriodIndex)
9197
with pytest.raises(Exception):
9298
func(idx)
9399

94-
elif isinstance(idx, DatetimeIndexOpsMixin):
100+
elif isinstance(idx, PeriodIndex):
95101
# raise TypeError or ValueError (PeriodIndex)
96102
with pytest.raises(Exception):
97103
func(idx)

0 commit comments

Comments
 (0)