Skip to content

Commit 74b125e

Browse files
authored
CLN: remove np17 compat (#42375)
1 parent dad3e7f commit 74b125e

File tree

10 files changed

+17
-69
lines changed

10 files changed

+17
-69
lines changed

pandas/__init__.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
del hard_dependencies, dependency, missing_dependencies
2020

2121
# numpy compat
22-
from pandas.compat import (
23-
np_version_under1p18 as _np_version_under1p18,
24-
is_numpy_dev as _is_numpy_dev,
25-
)
22+
from pandas.compat import is_numpy_dev as _is_numpy_dev
2623

2724
try:
2825
from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib

pandas/compat/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
is_numpy_dev,
1717
np_array_datetime64_compat,
1818
np_datetime64_compat,
19-
np_version_under1p18,
2019
np_version_under1p19,
2120
np_version_under1p20,
2221
)
@@ -151,7 +150,6 @@ def get_lzma_file(lzma):
151150
"is_numpy_dev",
152151
"np_array_datetime64_compat",
153152
"np_datetime64_compat",
154-
"np_version_under1p18",
155153
"np_version_under1p19",
156154
"np_version_under1p20",
157155
"pa_version_under1p0",

pandas/compat/numpy/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# numpy versioning
1010
_np_version = np.__version__
1111
_nlv = Version(_np_version)
12-
np_version_under1p18 = _nlv < Version("1.18")
1312
np_version_under1p19 = _nlv < Version("1.19")
1413
np_version_under1p20 = _nlv < Version("1.20")
1514
is_numpy_dev = _nlv.dev is not None

pandas/core/common.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
Scalar,
3636
T,
3737
)
38-
from pandas.compat import np_version_under1p18
3938

4039
from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
4140
from pandas.core.dtypes.common import (
@@ -433,7 +432,7 @@ def random_state(state: RandomState | None = None):
433432
if (
434433
is_integer(state)
435434
or is_array_like(state)
436-
or (not np_version_under1p18 and isinstance(state, np.random.BitGenerator))
435+
or isinstance(state, np.random.BitGenerator)
437436
):
438437
# error: Argument 1 to "RandomState" has incompatible type "Optional[Union[int,
439438
# Union[ExtensionArray, ndarray[Any, Any]], Generator, RandomState]]"; expected

pandas/tests/api/test_api.py

-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ class TestPDApi(Base):
193193
"_hashtable",
194194
"_lib",
195195
"_libs",
196-
"_np_version_under1p18",
197196
"_is_numpy_dev",
198197
"_testing",
199198
"_tslib",

pandas/tests/arrays/test_datetimelike.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
OutOfBoundsDatetime,
1111
Timestamp,
1212
)
13-
from pandas.compat import np_version_under1p18
1413
import pandas.util._test_decorators as td
1514

1615
import pandas as pd
@@ -288,12 +287,7 @@ def test_searchsorted(self):
288287
# GH#29884 match numpy convention on whether NaT goes
289288
# at the end or the beginning
290289
result = arr.searchsorted(NaT)
291-
if np_version_under1p18:
292-
# Following numpy convention, NaT goes at the beginning
293-
# (unlike NaN which goes at the end)
294-
assert result == 0
295-
else:
296-
assert result == 10
290+
assert result == 10
297291

298292
@pytest.mark.parametrize("box", [None, "index", "series"])
299293
def test_searchsorted_castable_strings(self, arr1d, box, request, string_storage):
@@ -1244,17 +1238,11 @@ def test_invalid_nat_setitem_array(arr, non_casting_nats):
12441238
],
12451239
)
12461240
def test_to_numpy_extra(arr):
1247-
if np_version_under1p18:
1248-
# np.isnan(NaT) raises, so use pandas'
1249-
isnan = pd.isna
1250-
else:
1251-
isnan = np.isnan
1252-
12531241
arr[0] = NaT
12541242
original = arr.copy()
12551243

12561244
result = arr.to_numpy()
1257-
assert isnan(result[0])
1245+
assert np.isnan(result[0])
12581246

12591247
result = arr.to_numpy(dtype="int64")
12601248
assert result[0] == -9223372036854775808

pandas/tests/frame/methods/test_sample.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
from pandas.compat import np_version_under1p18
5-
64
from pandas import (
75
DataFrame,
86
Index,
@@ -161,16 +159,8 @@ def test_sample_none_weights(self, obj):
161159
"func_str,arg",
162160
[
163161
("np.array", [2, 3, 1, 0]),
164-
pytest.param(
165-
"np.random.MT19937",
166-
3,
167-
marks=pytest.mark.skipif(np_version_under1p18, reason="NumPy<1.18"),
168-
),
169-
pytest.param(
170-
"np.random.PCG64",
171-
11,
172-
marks=pytest.mark.skipif(np_version_under1p18, reason="NumPy<1.18"),
173-
),
162+
("np.random.MT19937", 3),
163+
("np.random.PCG64", 11),
174164
],
175165
)
176166
def test_sample_random_state(self, func_str, arg, frame_or_series):

pandas/tests/indexes/period/test_searchsorted.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import pytest
33

44
from pandas._libs.tslibs import IncompatibleFrequency
5-
from pandas.compat import np_version_under1p18
65

76
from pandas import (
87
NaT,
@@ -28,13 +27,7 @@ def test_searchsorted(self, freq):
2827
p2 = Period("2014-01-04", freq=freq)
2928
assert pidx.searchsorted(p2) == 3
3029

31-
if np_version_under1p18:
32-
# GH#36254
33-
# Following numpy convention, NaT goes at the beginning
34-
# (unlike NaN which goes at the end)
35-
assert pidx.searchsorted(NaT) == 0
36-
else:
37-
assert pidx.searchsorted(NaT) == 5
30+
assert pidx.searchsorted(NaT) == 5
3831

3932
msg = "Input has different freq=H from PeriodArray"
4033
with pytest.raises(IncompatibleFrequency, match=msg):

pandas/tests/indexes/test_numpy_compat.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
from pandas.compat import np_version_under1p18
5-
64
from pandas import (
75
DatetimeIndex,
86
Float64Index,
@@ -82,22 +80,12 @@ def test_numpy_ufuncs_other(index, func, request):
8280
isinstance(index, DatetimeIndex)
8381
and index.tz is not None
8482
and func in [np.isfinite, np.isnan, np.isinf]
85-
and (
86-
not np_version_under1p18
87-
or (np_version_under1p18 and func is np.isfinite)
88-
)
8983
):
9084
mark = pytest.mark.xfail(reason="__array_ufunc__ is not defined")
9185
request.node.add_marker(mark)
9286

93-
if not np_version_under1p18 and func in [np.isfinite, np.isinf, np.isnan]:
94-
# numpy 1.18(dev) changed isinf and isnan to not raise on dt64/tfd64
95-
result = func(index)
96-
assert isinstance(result, np.ndarray)
97-
98-
elif func is np.isfinite:
99-
# ok under numpy >= 1.17
100-
# Results in bool array
87+
if func in (np.isfinite, np.isinf, np.isnan):
88+
# numpy 1.18 changed isinf and isnan to not raise on dt64/tfd64
10189
result = func(index)
10290
assert isinstance(result, np.ndarray)
10391
else:

pandas/tests/test_common.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import numpy as np
66
import pytest
77

8-
from pandas.compat import np_version_under1p18
9-
108
import pandas as pd
119
from pandas import Series
1210
import pandas._testing as tm
@@ -72,15 +70,14 @@ def test_random_state():
7270

7371
# Check BitGenerators
7472
# GH32503
75-
if not np_version_under1p18:
76-
assert (
77-
com.random_state(npr.MT19937(3)).uniform()
78-
== npr.RandomState(npr.MT19937(3)).uniform()
79-
)
80-
assert (
81-
com.random_state(npr.PCG64(11)).uniform()
82-
== npr.RandomState(npr.PCG64(11)).uniform()
83-
)
73+
assert (
74+
com.random_state(npr.MT19937(3)).uniform()
75+
== npr.RandomState(npr.MT19937(3)).uniform()
76+
)
77+
assert (
78+
com.random_state(npr.PCG64(11)).uniform()
79+
== npr.RandomState(npr.PCG64(11)).uniform()
80+
)
8481

8582
# Error for floats or strings
8683
msg = (

0 commit comments

Comments
 (0)