diff --git a/pandas/__init__.py b/pandas/__init__.py index db4043686bcbb..43f05617584cc 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -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 diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py index 369832e9bc05c..9c99488a57542 100644 --- a/pandas/compat/__init__.py +++ b/pandas/compat/__init__.py @@ -16,7 +16,6 @@ is_numpy_dev, np_array_datetime64_compat, np_datetime64_compat, - np_version_under1p18, np_version_under1p19, np_version_under1p20, ) @@ -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", diff --git a/pandas/compat/numpy/__init__.py b/pandas/compat/numpy/__init__.py index 4632626c40236..5b87257651a2d 100644 --- a/pandas/compat/numpy/__init__.py +++ b/pandas/compat/numpy/__init__.py @@ -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 diff --git a/pandas/core/common.py b/pandas/core/common.py index 84d18f81292c9..922959938b944 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -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 ( @@ -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 diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index 38984238ecf65..95dc1d82cb286 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -193,7 +193,6 @@ class TestPDApi(Base): "_hashtable", "_lib", "_libs", - "_np_version_under1p18", "_is_numpy_dev", "_testing", "_tslib", diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index 3f3f3a5ee8d18..1e150f1b431c7 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -10,7 +10,6 @@ OutOfBoundsDatetime, Timestamp, ) -from pandas.compat import np_version_under1p18 import pandas.util._test_decorators as td import pandas as pd @@ -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): @@ -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 diff --git a/pandas/tests/frame/methods/test_sample.py b/pandas/tests/frame/methods/test_sample.py index 90cdda7d7b3e9..366722531329a 100644 --- a/pandas/tests/frame/methods/test_sample.py +++ b/pandas/tests/frame/methods/test_sample.py @@ -1,8 +1,6 @@ import numpy as np import pytest -from pandas.compat import np_version_under1p18 - from pandas import ( DataFrame, Index, @@ -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): diff --git a/pandas/tests/indexes/period/test_searchsorted.py b/pandas/tests/indexes/period/test_searchsorted.py index af243eeccc7a4..27e998284c189 100644 --- a/pandas/tests/indexes/period/test_searchsorted.py +++ b/pandas/tests/indexes/period/test_searchsorted.py @@ -2,7 +2,6 @@ import pytest from pandas._libs.tslibs import IncompatibleFrequency -from pandas.compat import np_version_under1p18 from pandas import ( NaT, @@ -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): diff --git a/pandas/tests/indexes/test_numpy_compat.py b/pandas/tests/indexes/test_numpy_compat.py index f2ed96d0b65b8..92adc0570dee1 100644 --- a/pandas/tests/indexes/test_numpy_compat.py +++ b/pandas/tests/indexes/test_numpy_compat.py @@ -1,8 +1,6 @@ import numpy as np import pytest -from pandas.compat import np_version_under1p18 - from pandas import ( DatetimeIndex, Float64Index, @@ -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: diff --git a/pandas/tests/test_common.py b/pandas/tests/test_common.py index f123f0ac9f5f8..a9b2176fba19a 100644 --- a/pandas/tests/test_common.py +++ b/pandas/tests/test_common.py @@ -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 @@ -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 = (