From 5b1b36173ea9317b1a3a1f61ec114ef15d3bbe6c Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Thu, 13 Apr 2023 14:41:24 -0500 Subject: [PATCH 1/6] DEPS: drop no 1.20 --- pandas/compat/__init__.py | 6 +----- pandas/compat/numpy/__init__.py | 4 +--- pandas/core/array_algos/putmask.py | 4 ++-- pandas/tests/extension/base/casting.py | 9 +++------ pandas/tests/frame/methods/test_quantile.py | 15 +-------------- 5 files changed, 8 insertions(+), 30 deletions(-) diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py index 656d5861912b4..745b20dc4e764 100644 --- a/pandas/compat/__init__.py +++ b/pandas/compat/__init__.py @@ -22,10 +22,7 @@ PYPY, ) import pandas.compat.compressors -from pandas.compat.numpy import ( - is_numpy_dev, - np_version_under1p21, -) +from pandas.compat.numpy import is_numpy_dev from pandas.compat.pyarrow import ( pa_version_under7p0, pa_version_under8p0, @@ -159,7 +156,6 @@ def get_lzma_file() -> type[pandas.compat.compressors.LZMAFile]: __all__ = [ "is_numpy_dev", - "np_version_under1p21", "pa_version_under7p0", "pa_version_under8p0", "pa_version_under9p0", diff --git a/pandas/compat/numpy/__init__.py b/pandas/compat/numpy/__init__.py index 6f31358dabe86..f4609dd333cba 100644 --- a/pandas/compat/numpy/__init__.py +++ b/pandas/compat/numpy/__init__.py @@ -6,12 +6,10 @@ # numpy versioning _np_version = np.__version__ _nlv = Version(_np_version) -np_version_under1p21 = _nlv < Version("1.21") np_version_under1p22 = _nlv < Version("1.22") -np_version_gte1p22 = _nlv >= Version("1.22") np_version_gte1p24 = _nlv >= Version("1.24") is_numpy_dev = _nlv.dev is not None -_min_numpy_ver = "1.20.3" +_min_numpy_ver = "1.21.3" if is_numpy_dev or not np_version_under1p22: np_percentile_argname = "method" diff --git a/pandas/core/array_algos/putmask.py b/pandas/core/array_algos/putmask.py index 3b9aad0790df9..99dff68036d16 100644 --- a/pandas/core/array_algos/putmask.py +++ b/pandas/core/array_algos/putmask.py @@ -11,7 +11,7 @@ import numpy as np from pandas._libs import lib -from pandas.compat import np_version_under1p21 +from pandas.compat import np_version_under1p22 from pandas.core.dtypes.cast import infer_dtype_from from pandas.core.dtypes.common import is_list_like @@ -73,7 +73,7 @@ def putmask_without_repeat( mask : np.ndarray[bool] new : Any """ - if np_version_under1p21: + if np_version_under1p22: new = setitem_datetimelike_compat(values, mask.sum(), new) if getattr(new, "ndim", 0) >= 1: diff --git a/pandas/tests/extension/base/casting.py b/pandas/tests/extension/base/casting.py index 59b8679881bce..e24c3b4569e3e 100644 --- a/pandas/tests/extension/base/casting.py +++ b/pandas/tests/extension/base/casting.py @@ -1,7 +1,6 @@ import numpy as np import pytest -from pandas.compat import np_version_under1p21 import pandas.util._test_decorators as td import pandas as pd @@ -31,11 +30,9 @@ def test_astype_object_frame(self, all_data): assert isinstance(result._mgr.arrays[0], np.ndarray) assert result._mgr.arrays[0].dtype == np.dtype(object) - # earlier numpy raises TypeError on e.g. np.dtype(np.int64) == "Int64" - if not np_version_under1p21: - # check that we can compare the dtypes - comp = result.dtypes == df.dtypes - assert not comp.any() + # check that we can compare the dtypes + comp = result.dtypes == df.dtypes + assert not comp.any() def test_tolist(self, data): result = pd.Series(data).tolist() diff --git a/pandas/tests/frame/methods/test_quantile.py b/pandas/tests/frame/methods/test_quantile.py index 5d2833f6fbfdf..87badfd710a62 100644 --- a/pandas/tests/frame/methods/test_quantile.py +++ b/pandas/tests/frame/methods/test_quantile.py @@ -1,10 +1,7 @@ import numpy as np import pytest -from pandas.compat.numpy import ( - np_percentile_argname, - np_version_under1p21, -) +from pandas.compat.numpy import np_percentile_argname import pandas as pd from pandas import ( @@ -848,11 +845,6 @@ def test_quantile_ea(self, request, obj, index): qs = [0.5, 0, 1] result = self.compute_quantile(obj, qs) - if np_version_under1p21 and index.dtype == "timedelta64[ns]": - msg = "failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood" - mark = pytest.mark.xfail(reason=msg, raises=TypeError) - request.node.add_marker(mark) - exp_dtype = index.dtype if index.dtype == "Int64": # match non-nullable casting behavior @@ -914,11 +906,6 @@ def test_quantile_ea_scalar(self, request, obj, index): qs = 0.5 result = self.compute_quantile(obj, qs) - if np_version_under1p21 and index.dtype == "timedelta64[ns]": - msg = "failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood" - mark = pytest.mark.xfail(reason=msg, raises=TypeError) - request.node.add_marker(mark) - exp_dtype = index.dtype if index.dtype == "Int64": exp_dtype = "Float64" From 713f23ba1edbdb32bca08499489e2540806916d6 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Thu, 13 Apr 2023 14:46:00 -0500 Subject: [PATCH 2/6] update min version in doc --- ci/deps/actions-38-minimum_versions.yaml | 2 +- doc/source/getting_started/install.rst | 2 +- pandas/compat/numpy/__init__.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/deps/actions-38-minimum_versions.yaml b/ci/deps/actions-38-minimum_versions.yaml index 2eb2ade8a2934..1a4a4e163678e 100644 --- a/ci/deps/actions-38-minimum_versions.yaml +++ b/ci/deps/actions-38-minimum_versions.yaml @@ -19,7 +19,7 @@ dependencies: # required dependencies - python-dateutil=2.8.2 - - numpy=1.20.3 + - numpy=1.21.6 - pytz=2020.1 # optional dependencies diff --git a/doc/source/getting_started/install.rst b/doc/source/getting_started/install.rst index f34676edd26dc..e08628816bd8d 100644 --- a/doc/source/getting_started/install.rst +++ b/doc/source/getting_started/install.rst @@ -268,7 +268,7 @@ pandas requires the following dependencies. ================================================================ ========================== Package Minimum supported version ================================================================ ========================== -`NumPy `__ 1.20.3 +`NumPy `__ 1.21.6 `python-dateutil `__ 2.8.2 `pytz `__ 2020.1 ================================================================ ========================== diff --git a/pandas/compat/numpy/__init__.py b/pandas/compat/numpy/__init__.py index f4609dd333cba..226bd2e5b3a52 100644 --- a/pandas/compat/numpy/__init__.py +++ b/pandas/compat/numpy/__init__.py @@ -9,7 +9,7 @@ np_version_under1p22 = _nlv < Version("1.22") np_version_gte1p24 = _nlv >= Version("1.24") is_numpy_dev = _nlv.dev is not None -_min_numpy_ver = "1.21.3" +_min_numpy_ver = "1.21.6" if is_numpy_dev or not np_version_under1p22: np_percentile_argname = "method" From 54d9e793b56f76e2a15e6929b2c0c829e6d08d54 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Thu, 13 Apr 2023 15:32:02 -0500 Subject: [PATCH 3/6] remove more compat --- pandas/compat/numpy/__init__.py | 5 +---- pandas/core/array_algos/putmask.py | 4 ---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/pandas/compat/numpy/__init__.py b/pandas/compat/numpy/__init__.py index 226bd2e5b3a52..fbc04386bcef2 100644 --- a/pandas/compat/numpy/__init__.py +++ b/pandas/compat/numpy/__init__.py @@ -11,10 +11,7 @@ is_numpy_dev = _nlv.dev is not None _min_numpy_ver = "1.21.6" -if is_numpy_dev or not np_version_under1p22: - np_percentile_argname = "method" -else: - np_percentile_argname = "interpolation" +np_percentile_argname = "interpolation" if np_version_under1p22 else "method" if _nlv < Version(_min_numpy_ver): diff --git a/pandas/core/array_algos/putmask.py b/pandas/core/array_algos/putmask.py index 99aea619bc277..8c8d962e7782b 100644 --- a/pandas/core/array_algos/putmask.py +++ b/pandas/core/array_algos/putmask.py @@ -11,7 +11,6 @@ import numpy as np from pandas._libs import lib -from pandas.compat import np_version_under1p22 from pandas.core.dtypes.cast import infer_dtype_from from pandas.core.dtypes.common import is_list_like @@ -73,9 +72,6 @@ def putmask_without_repeat( mask : np.ndarray[bool] new : Any """ - if np_version_under1p22: - new = setitem_datetimelike_compat(values, mask.sum(), new) - if getattr(new, "ndim", 0) >= 1: new = new.astype(values.dtype, copy=False) From 6b148452fb9eaaf41d9b5709a2407fad0c945fb8 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Wed, 19 Apr 2023 17:41:39 -0500 Subject: [PATCH 4/6] remove more compat, fix doc and ci --- .github/workflows/sdist.yml | 6 +++--- doc/source/whatsnew/v2.1.0.rst | 2 ++ pandas/tests/extension/base/dtype.py | 9 +-------- pyproject.toml | 3 +-- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.github/workflows/sdist.yml b/.github/workflows/sdist.yml index cd99a1e3e805c..460369f45e900 100644 --- a/.github/workflows/sdist.yml +++ b/.github/workflows/sdist.yml @@ -81,11 +81,11 @@ jobs: run: | case "${{matrix.python-version}}" in 3.8) - pip install numpy==1.20.3 ;; + pip install numpy==1.21.6 ;; 3.9) - pip install numpy==1.20.3 ;; + pip install numpy==1.21.6 ;; 3.10) - pip install numpy==1.21.2 ;; + pip install numpy==1.21.6 ;; 3.11) pip install numpy==1.23.2 ;; esac diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 22a2931519ffd..6de372838d4e1 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -131,6 +131,8 @@ If installed, we now require: +-----------------+-----------------+----------+---------+ | Package | Minimum Version | Required | Changed | +=================+=================+==========+=========+ +| numpy | 1.21.6 | X | X | ++-----------------+-----------------+----------+---------+ | mypy (dev) | 1.2 | | X | +-----------------+-----------------+----------+---------+ | beautifulsoup4 | 4.11.1 | | X | diff --git a/pandas/tests/extension/base/dtype.py b/pandas/tests/extension/base/dtype.py index 392a75f8a69a7..f940191174849 100644 --- a/pandas/tests/extension/base/dtype.py +++ b/pandas/tests/extension/base/dtype.py @@ -62,14 +62,7 @@ def test_check_dtype(self, data): {"A": pd.Series(data, dtype=dtype), "B": data, "C": "foo", "D": 1} ) result = df.dtypes == str(dtype) - - try: - new_numpy_behavior = np.dtype("int64") != "Int64" - except TypeError: - # numpy<=1.20.3 this comparison could raise or in some cases - # come back True - new_numpy_behavior = True - assert new_numpy_behavior + assert np.dtype("int64") != "Int64" expected = pd.Series([True, True, False, False], index=list("ABCD")) diff --git a/pyproject.toml b/pyproject.toml index d5298ed186043..8b5603ecb7c7b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,8 +23,7 @@ authors = [ license = {file = 'LICENSE'} requires-python = '>=3.8' dependencies = [ - "numpy>=1.20.3; python_version<'3.10'", - "numpy>=1.21.0; python_version>='3.10'", + "numpy>=1.21.6; python_version<'3.11'", "numpy>=1.23.2; python_version>='3.11'", "python-dateutil>=2.8.2", "pytz>=2020.1", From ff7de51c414848fefaa105543601184c2b1b9402 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Wed, 19 Apr 2023 20:32:59 -0500 Subject: [PATCH 5/6] remove xfail in arrow test --- pandas/tests/extension/test_arrow.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index f9d94d39fceb1..32e1e3cdf049b 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -600,15 +600,7 @@ def test_in_numeric_groupby(self, data_for_grouping): class TestBaseDtype(base.BaseDtypeTests): - def test_check_dtype(self, data, request): - pa_dtype = data.dtype.pyarrow_dtype - if pa.types.is_decimal(pa_dtype) and pa_version_under8p0: - request.node.add_marker( - pytest.mark.xfail( - raises=ValueError, - reason="decimal string repr affects numpy comparison", - ) - ) + def test_check_dtype(self, data): super().test_check_dtype(data) def test_construct_from_string_own_name(self, dtype, request): From fbee17c44eb33d84df22d27a9b0d74386b1e021a Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Wed, 19 Apr 2023 21:32:49 -0500 Subject: [PATCH 6/6] fix pylint --- pandas/tests/extension/test_arrow.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index 32e1e3cdf049b..25e643f53f925 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -600,9 +600,6 @@ def test_in_numeric_groupby(self, data_for_grouping): class TestBaseDtype(base.BaseDtypeTests): - def test_check_dtype(self, data): - super().test_check_dtype(data) - def test_construct_from_string_own_name(self, dtype, request): pa_dtype = dtype.pyarrow_dtype if pa.types.is_decimal(pa_dtype):