Skip to content

Commit

Permalink
CLN: remove np17 compat (#42375)
Browse files Browse the repository at this point in the history
  • Loading branch information
fangchenli authored Jul 6, 2021
1 parent dad3e7f commit 74b125e
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 69 deletions.
5 changes: 1 addition & 4 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
del hard_dependencies, dependency, missing_dependencies

# numpy compat
from pandas.compat import (
np_version_under1p18 as _np_version_under1p18,
is_numpy_dev as _is_numpy_dev,
)
from pandas.compat import is_numpy_dev as _is_numpy_dev

try:
from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
Expand Down
2 changes: 0 additions & 2 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
is_numpy_dev,
np_array_datetime64_compat,
np_datetime64_compat,
np_version_under1p18,
np_version_under1p19,
np_version_under1p20,
)
Expand Down Expand Up @@ -151,7 +150,6 @@ def get_lzma_file(lzma):
"is_numpy_dev",
"np_array_datetime64_compat",
"np_datetime64_compat",
"np_version_under1p18",
"np_version_under1p19",
"np_version_under1p20",
"pa_version_under1p0",
Expand Down
1 change: 0 additions & 1 deletion pandas/compat/numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# numpy versioning
_np_version = np.__version__
_nlv = Version(_np_version)
np_version_under1p18 = _nlv < Version("1.18")
np_version_under1p19 = _nlv < Version("1.19")
np_version_under1p20 = _nlv < Version("1.20")
is_numpy_dev = _nlv.dev is not None
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
Scalar,
T,
)
from pandas.compat import np_version_under1p18

from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -433,7 +432,7 @@ def random_state(state: RandomState | None = None):
if (
is_integer(state)
or is_array_like(state)
or (not np_version_under1p18 and isinstance(state, np.random.BitGenerator))
or isinstance(state, np.random.BitGenerator)
):
# error: Argument 1 to "RandomState" has incompatible type "Optional[Union[int,
# Union[ExtensionArray, ndarray[Any, Any]], Generator, RandomState]]"; expected
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ class TestPDApi(Base):
"_hashtable",
"_lib",
"_libs",
"_np_version_under1p18",
"_is_numpy_dev",
"_testing",
"_tslib",
Expand Down
16 changes: 2 additions & 14 deletions pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
OutOfBoundsDatetime,
Timestamp,
)
from pandas.compat import np_version_under1p18
import pandas.util._test_decorators as td

import pandas as pd
Expand Down Expand Up @@ -288,12 +287,7 @@ def test_searchsorted(self):
# GH#29884 match numpy convention on whether NaT goes
# at the end or the beginning
result = arr.searchsorted(NaT)
if np_version_under1p18:
# Following numpy convention, NaT goes at the beginning
# (unlike NaN which goes at the end)
assert result == 0
else:
assert result == 10
assert result == 10

@pytest.mark.parametrize("box", [None, "index", "series"])
def test_searchsorted_castable_strings(self, arr1d, box, request, string_storage):
Expand Down Expand Up @@ -1244,17 +1238,11 @@ def test_invalid_nat_setitem_array(arr, non_casting_nats):
],
)
def test_to_numpy_extra(arr):
if np_version_under1p18:
# np.isnan(NaT) raises, so use pandas'
isnan = pd.isna
else:
isnan = np.isnan

arr[0] = NaT
original = arr.copy()

result = arr.to_numpy()
assert isnan(result[0])
assert np.isnan(result[0])

result = arr.to_numpy(dtype="int64")
assert result[0] == -9223372036854775808
Expand Down
14 changes: 2 additions & 12 deletions pandas/tests/frame/methods/test_sample.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
import pytest

from pandas.compat import np_version_under1p18

from pandas import (
DataFrame,
Index,
Expand Down Expand Up @@ -161,16 +159,8 @@ def test_sample_none_weights(self, obj):
"func_str,arg",
[
("np.array", [2, 3, 1, 0]),
pytest.param(
"np.random.MT19937",
3,
marks=pytest.mark.skipif(np_version_under1p18, reason="NumPy<1.18"),
),
pytest.param(
"np.random.PCG64",
11,
marks=pytest.mark.skipif(np_version_under1p18, reason="NumPy<1.18"),
),
("np.random.MT19937", 3),
("np.random.PCG64", 11),
],
)
def test_sample_random_state(self, func_str, arg, frame_or_series):
Expand Down
9 changes: 1 addition & 8 deletions pandas/tests/indexes/period/test_searchsorted.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pytest

from pandas._libs.tslibs import IncompatibleFrequency
from pandas.compat import np_version_under1p18

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

if np_version_under1p18:
# GH#36254
# Following numpy convention, NaT goes at the beginning
# (unlike NaN which goes at the end)
assert pidx.searchsorted(NaT) == 0
else:
assert pidx.searchsorted(NaT) == 5
assert pidx.searchsorted(NaT) == 5

msg = "Input has different freq=H from PeriodArray"
with pytest.raises(IncompatibleFrequency, match=msg):
Expand Down
16 changes: 2 additions & 14 deletions pandas/tests/indexes/test_numpy_compat.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
import pytest

from pandas.compat import np_version_under1p18

from pandas import (
DatetimeIndex,
Float64Index,
Expand Down Expand Up @@ -82,22 +80,12 @@ def test_numpy_ufuncs_other(index, func, request):
isinstance(index, DatetimeIndex)
and index.tz is not None
and func in [np.isfinite, np.isnan, np.isinf]
and (
not np_version_under1p18
or (np_version_under1p18 and func is np.isfinite)
)
):
mark = pytest.mark.xfail(reason="__array_ufunc__ is not defined")
request.node.add_marker(mark)

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(index)
assert isinstance(result, np.ndarray)

elif func is np.isfinite:
# ok under numpy >= 1.17
# Results in bool array
if func in (np.isfinite, np.isinf, np.isnan):
# numpy 1.18 changed isinf and isnan to not raise on dt64/tfd64
result = func(index)
assert isinstance(result, np.ndarray)
else:
Expand Down
19 changes: 8 additions & 11 deletions pandas/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import numpy as np
import pytest

from pandas.compat import np_version_under1p18

import pandas as pd
from pandas import Series
import pandas._testing as tm
Expand Down Expand Up @@ -72,15 +70,14 @@ def test_random_state():

# Check BitGenerators
# GH32503
if not np_version_under1p18:
assert (
com.random_state(npr.MT19937(3)).uniform()
== npr.RandomState(npr.MT19937(3)).uniform()
)
assert (
com.random_state(npr.PCG64(11)).uniform()
== npr.RandomState(npr.PCG64(11)).uniform()
)
assert (
com.random_state(npr.MT19937(3)).uniform()
== npr.RandomState(npr.MT19937(3)).uniform()
)
assert (
com.random_state(npr.PCG64(11)).uniform()
== npr.RandomState(npr.PCG64(11)).uniform()
)

# Error for floats or strings
msg = (
Expand Down

0 comments on commit 74b125e

Please sign in to comment.