From 56274db9096ced2de0db2c1dea5c93cce21319fd Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 19 Jul 2022 22:57:28 -0700 Subject: [PATCH 01/12] DEPS: drop np19 support --- .github/workflows/sdist.yml | 4 +-- doc/source/getting_started/install.rst | 2 +- doc/source/whatsnew/v1.5.0.rst | 2 +- pandas/compat/__init__.py | 6 +--- pandas/compat/numpy/__init__.py | 3 +- pandas/core/array_algos/putmask.py | 31 ------------------- .../arrays/floating/test_construction.py | 7 ----- .../tests/arrays/sparse/test_arithmetics.py | 29 ----------------- pandas/tests/extension/base/casting.py | 10 ++---- pandas/tests/extension/test_sparse.py | 10 ++---- pandas/tests/frame/indexing/test_where.py | 3 -- pandas/tests/frame/methods/test_replace.py | 8 ----- pandas/tests/series/test_constructors.py | 4 --- setup.cfg | 4 +-- 14 files changed, 13 insertions(+), 110 deletions(-) diff --git a/.github/workflows/sdist.yml b/.github/workflows/sdist.yml index 2e1ffe6d0d17e..1a06ea31ccbb8 100644 --- a/.github/workflows/sdist.yml +++ b/.github/workflows/sdist.yml @@ -79,9 +79,9 @@ jobs: run: | case "${{matrix.python-version}}" in 3.8) - pip install numpy==1.19.5 ;; + pip install numpy==1.20.3 ;; 3.9) - pip install numpy==1.19.5 ;; + pip install numpy==1.20.3 ;; 3.10) pip install numpy==1.21.2 ;; esac diff --git a/doc/source/getting_started/install.rst b/doc/source/getting_started/install.rst index 5d9bfd97030b5..605a69b26a646 100644 --- a/doc/source/getting_started/install.rst +++ b/doc/source/getting_started/install.rst @@ -235,7 +235,7 @@ Dependencies ================================================================ ========================== Package Minimum supported version ================================================================ ========================== -`NumPy `__ 1.19.5 +`NumPy `__ 1.20.3 `python-dateutil `__ 2.8.1 `pytz `__ 2020.1 ================================================================ ========================== diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 090fea57872c5..fece4eca662be 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -416,7 +416,7 @@ If installed, we now require: +-----------------+-----------------+----------+---------+ | Package | Minimum Version | Required | Changed | +=================+=================+==========+=========+ -| numpy | 1.19.5 | X | X | +| numpy | 1.20.3 | X | X | +-----------------+-----------------+----------+---------+ | mypy (dev) | 0.960 | | X | +-----------------+-----------------+----------+---------+ diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py index 5db859897b663..d8cc1c019c71e 100644 --- a/pandas/compat/__init__.py +++ b/pandas/compat/__init__.py @@ -15,10 +15,7 @@ from typing import TYPE_CHECKING from pandas._typing import F -from pandas.compat.numpy import ( - is_numpy_dev, - np_version_under1p20, -) +from pandas.compat.numpy import is_numpy_dev from pandas.compat.pyarrow import ( pa_version_under1p01, pa_version_under2p0, @@ -151,7 +148,6 @@ def get_lzma_file() -> type[lzma.LZMAFile]: __all__ = [ "is_numpy_dev", - "np_version_under1p20", "pa_version_under1p01", "pa_version_under2p0", "pa_version_under3p0", diff --git a/pandas/compat/numpy/__init__.py b/pandas/compat/numpy/__init__.py index 803f495b311b9..a7cffba501d67 100644 --- a/pandas/compat/numpy/__init__.py +++ b/pandas/compat/numpy/__init__.py @@ -6,11 +6,10 @@ # numpy versioning _np_version = np.__version__ _nlv = Version(_np_version) -np_version_under1p20 = _nlv < Version("1.20") np_version_under1p22 = _nlv < Version("1.22") np_version_gte1p22 = _nlv >= Version("1.22") is_numpy_dev = _nlv.dev is not None -_min_numpy_ver = "1.19.5" +_min_numpy_ver = "1.20.3" is_numpy_min = _nlv == Version(_min_numpy_ver) if is_numpy_dev or not np_version_under1p22: diff --git a/pandas/core/array_algos/putmask.py b/pandas/core/array_algos/putmask.py index 84160344437b5..89ed6da3b5d78 100644 --- a/pandas/core/array_algos/putmask.py +++ b/pandas/core/array_algos/putmask.py @@ -12,9 +12,7 @@ ArrayLike, npt, ) -from pandas.compat import np_version_under1p20 -from pandas.core.dtypes.cast import infer_dtype_from from pandas.core.dtypes.common import is_list_like from pandas.core.arrays import ExtensionArray @@ -66,9 +64,6 @@ def putmask_without_repeat( mask : np.ndarray[bool] new : Any """ - if np_version_under1p20: - new = setitem_datetimelike_compat(values, mask.sum(), new) - if getattr(new, "ndim", 0) >= 1: new = new.astype(values.dtype, copy=False) @@ -76,9 +71,6 @@ def putmask_without_repeat( nlocs = mask.sum() if nlocs > 0 and is_list_like(new) and getattr(new, "ndim", 1) == 1: shape = np.shape(new) - # np.shape compat for if setitem_datetimelike_compat - # changed arraylike to list e.g. test_where_dt64_2d - if nlocs == shape[-1]: # GH#30567 # If length of ``new`` is less than the length of ``values``, @@ -122,26 +114,3 @@ def extract_bool_array(mask: ArrayLike) -> npt.NDArray[np.bool_]: mask = np.asarray(mask, dtype=bool) return mask - - -def setitem_datetimelike_compat(values: np.ndarray, num_set: int, other): - """ - Parameters - ---------- - values : np.ndarray - num_set : int - For putmask, this is mask.sum() - other : Any - """ - if values.dtype == object: - dtype, _ = infer_dtype_from(other, pandas_dtype=True) - - if isinstance(dtype, np.dtype) and dtype.kind in ["m", "M"]: - # https://github.com/numpy/numpy/issues/12550 - # timedelta64 will incorrectly cast to int - if not is_list_like(other): - other = [other] * num_set - else: - other = list(other) - - return other diff --git a/pandas/tests/arrays/floating/test_construction.py b/pandas/tests/arrays/floating/test_construction.py index ebce80cba237d..2dcd54f443029 100644 --- a/pandas/tests/arrays/floating/test_construction.py +++ b/pandas/tests/arrays/floating/test_construction.py @@ -1,8 +1,6 @@ import numpy as np import pytest -from pandas.compat import np_version_under1p20 - import pandas as pd import pandas._testing as tm from pandas.core.arrays import FloatingArray @@ -54,11 +52,6 @@ def test_floating_array_disallows_float16(): def test_floating_array_disallows_Float16_dtype(request): # GH#44715 - if np_version_under1p20: - # https://github.com/numpy/numpy/issues/20512 - mark = pytest.mark.xfail(reason="numpy does not raise on np.dtype('Float16')") - request.node.add_marker(mark) - with pytest.raises(TypeError, match="data type 'Float16' not understood"): pd.array([1.0, 2.0], dtype="Float16") diff --git a/pandas/tests/arrays/sparse/test_arithmetics.py b/pandas/tests/arrays/sparse/test_arithmetics.py index 9593152735ed6..1a32c995f4afa 100644 --- a/pandas/tests/arrays/sparse/test_arithmetics.py +++ b/pandas/tests/arrays/sparse/test_arithmetics.py @@ -3,11 +3,8 @@ import numpy as np import pytest -from pandas.compat import np_version_under1p20 - import pandas as pd import pandas._testing as tm -from pandas.core import ops from pandas.core.arrays.sparse import ( SparseArray, SparseDtype, @@ -121,19 +118,7 @@ def test_float_scalar( self, kind, mix, all_arithmetic_functions, fill_value, scalar, request ): op = all_arithmetic_functions - - if np_version_under1p20: - if op in [operator.floordiv, ops.rfloordiv]: - if op is operator.floordiv and scalar != 0: - pass - elif op is ops.rfloordiv and scalar == 0: - pass - else: - mark = pytest.mark.xfail(raises=AssertionError, reason="GH#38172") - request.node.add_marker(mark) - values = np.array([np.nan, 1, 2, 0, np.nan, 0, 1, 2, 1, np.nan]) - a = SparseArray(values, kind=kind, fill_value=fill_value) self._check_numeric_ops(a, scalar, values, scalar, mix, op) @@ -171,14 +156,6 @@ def test_float_same_index_with_nans( ): # when sp_index are the same op = all_arithmetic_functions - - if ( - np_version_under1p20 - and op is ops.rfloordiv - and not (mix and kind == "block") - ): - mark = pytest.mark.xfail(raises=AssertionError, reason="GH#38172") - request.node.add_marker(mark) values = np.array([np.nan, 1, 2, 0, np.nan, 0, 1, 2, 1, np.nan]) rvalues = np.array([np.nan, 2, 3, 4, np.nan, 0, 1, 3, 2, np.nan]) @@ -353,13 +330,7 @@ def test_bool_array_logical(self, kind, fill_value): def test_mixed_array_float_int(self, kind, mix, all_arithmetic_functions, request): op = all_arithmetic_functions - - if np_version_under1p20 and op in [operator.floordiv, ops.rfloordiv] and mix: - mark = pytest.mark.xfail(raises=AssertionError, reason="GH#38172") - request.node.add_marker(mark) - rdtype = "int64" - values = np.array([np.nan, 1, 2, 0, np.nan, 0, 1, 2, 1, np.nan]) rvalues = np.array([2, 0, 2, 3, 0, 0, 1, 5, 2, 0], dtype=rdtype) diff --git a/pandas/tests/extension/base/casting.py b/pandas/tests/extension/base/casting.py index 4987751f31dac..86dbbe4e6ef10 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_under1p20 import pandas.util._test_decorators as td import pandas as pd @@ -31,12 +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" - # instead of returning False - if not np_version_under1p20: - # 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/extension/test_sparse.py b/pandas/tests/extension/test_sparse.py index d13f6dab1cc9b..60eef0d8097e4 100644 --- a/pandas/tests/extension/test_sparse.py +++ b/pandas/tests/extension/test_sparse.py @@ -17,7 +17,6 @@ import numpy as np import pytest -from pandas.compat import np_version_under1p20 from pandas.errors import PerformanceWarning from pandas.core.dtypes.common import is_object_dtype @@ -415,12 +414,9 @@ def test_astype_object_frame(self, all_data): result = df.astype(object) assert is_object_dtype(result._mgr.arrays[0].dtype) - # earlier numpy raises TypeError on e.g. np.dtype(np.int64) == "Int64" - # instead of returning False - if not np_version_under1p20: - # 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_astype_str(self, data): with tm.assert_produces_warning(FutureWarning, match="astype from Sparse"): diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index 5b9883f3866e7..aa55a7c91d0e6 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -4,8 +4,6 @@ import numpy as np import pytest -from pandas.compat import np_version_under1p20 - from pandas.core.dtypes.common import is_scalar import pandas as pd @@ -1006,7 +1004,6 @@ def _check_where_equivalences(df, mask, other, expected): tm.assert_frame_equal(df, expected) -@pytest.mark.xfail(np_version_under1p20, reason="failed on Numpy 1.19.5") def test_where_dt64_2d(): dti = date_range("2016-01-01", periods=6) dta = dti._data.reshape(3, 2) diff --git a/pandas/tests/frame/methods/test_replace.py b/pandas/tests/frame/methods/test_replace.py index f7504e9173bf5..555d24e747f44 100644 --- a/pandas/tests/frame/methods/test_replace.py +++ b/pandas/tests/frame/methods/test_replace.py @@ -6,8 +6,6 @@ import numpy as np import pytest -from pandas.compat import np_version_under1p20 - import pandas as pd from pandas import ( DataFrame, @@ -1316,12 +1314,6 @@ def test_replace_commutative(self, df, to_replace, exp): ) def test_replace_replacer_dtype(self, request, replacer): # GH26632 - if np.isscalar(replacer) and replacer.dtype.itemsize < 8: - request.node.add_marker( - pytest.mark.xfail( - np_version_under1p20, reason="np.putmask doesn't coerce dtype" - ) - ) df = DataFrame(["a"]) result = df.replace({"a": replacer, "b": replacer}) expected = DataFrame([replacer]) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 4e4ee4fd12d5f..0f6970bf7cff8 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -13,7 +13,6 @@ iNaT, lib, ) -from pandas.compat.numpy import np_version_under1p20 import pandas.util._test_decorators as td from pandas.core.dtypes.common import ( @@ -1882,9 +1881,6 @@ def test_constructor_bool_dtype_missing_values(self): @pytest.mark.filterwarnings( "ignore:elementwise comparison failed:DeprecationWarning" ) - @pytest.mark.xfail( - np_version_under1p20, reason="np.array([td64nat, float, float]) raises" - ) @pytest.mark.parametrize("func", [Series, DataFrame, Index, pd.array]) def test_constructor_mismatched_null_nullable_dtype( self, func, any_numeric_ea_dtype diff --git a/setup.cfg b/setup.cfg index b191930acf4c5..8f7cfc288ecdb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,9 +31,7 @@ project_urls = [options] packages = find: install_requires = - numpy>=1.18.5; platform_machine!='aarch64' and platform_machine!='arm64' and python_version<'3.10' - numpy>=1.19.2; platform_machine=='aarch64' and python_version<'3.10' - numpy>=1.20.0; platform_machine=='arm64' and python_version<'3.10' + numpy>=1.20.3; python_version<'3.10' numpy>=1.21.0; python_version>='3.10' python-dateutil>=2.8.1 pytz>=2020.1 From c46aeb5d3ac9ac6872e816c1c05d6655d2ac3451 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 19 Jul 2022 23:16:25 -0700 Subject: [PATCH 02/12] roll back --- pandas/core/array_algos/putmask.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pandas/core/array_algos/putmask.py b/pandas/core/array_algos/putmask.py index 89ed6da3b5d78..a3249a2465b98 100644 --- a/pandas/core/array_algos/putmask.py +++ b/pandas/core/array_algos/putmask.py @@ -13,6 +13,7 @@ npt, ) +from pandas.core.dtypes.cast import infer_dtype_from from pandas.core.dtypes.common import is_list_like from pandas.core.arrays import ExtensionArray @@ -71,6 +72,8 @@ def putmask_without_repeat( nlocs = mask.sum() if nlocs > 0 and is_list_like(new) and getattr(new, "ndim", 1) == 1: shape = np.shape(new) + # np.shape compat for if setitem_datetimelike_compat + # changed arraylike to list e.g. test_where_dt64_2d if nlocs == shape[-1]: # GH#30567 # If length of ``new`` is less than the length of ``values``, @@ -114,3 +117,26 @@ def extract_bool_array(mask: ArrayLike) -> npt.NDArray[np.bool_]: mask = np.asarray(mask, dtype=bool) return mask + + +def setitem_datetimelike_compat(values: np.ndarray, num_set: int, other): + """ + Parameters + ---------- + values : np.ndarray + num_set : int + For putmask, this is mask.sum() + other : Any + """ + if values.dtype == object: + dtype, _ = infer_dtype_from(other, pandas_dtype=True) + + if isinstance(dtype, np.dtype) and dtype.kind in ["m", "M"]: + # https://github.com/numpy/numpy/issues/12550 + # timedelta64 will incorrectly cast to int + if not is_list_like(other): + other = [other] * num_set + else: + other = list(other) + + return other From abc3c89c5a8ff0dbe99c117fe681e9d1ac9df9ab Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 19 Jul 2022 23:17:39 -0700 Subject: [PATCH 03/12] update ci dep file --- ci/deps/actions-38-minimum_versions.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/deps/actions-38-minimum_versions.yaml b/ci/deps/actions-38-minimum_versions.yaml index 3ab27830060b2..89ebabbbc7469 100644 --- a/ci/deps/actions-38-minimum_versions.yaml +++ b/ci/deps/actions-38-minimum_versions.yaml @@ -17,7 +17,7 @@ dependencies: # required dependencies - python-dateutil=2.8.1 - - numpy=1.19.5 + - numpy=1.20.3 - pytz=2020.1 # optional dependencies From b1b2b8ba63b8c9bb4185cae92cb9aab5015de427 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Wed, 20 Jul 2022 01:10:07 -0700 Subject: [PATCH 04/12] add some compat back --- pandas/compat/__init__.py | 6 +++++- pandas/compat/numpy/__init__.py | 1 + pandas/tests/extension/base/casting.py | 8 +++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py index d8cc1c019c71e..ea4209f169b9f 100644 --- a/pandas/compat/__init__.py +++ b/pandas/compat/__init__.py @@ -15,7 +15,10 @@ from typing import TYPE_CHECKING from pandas._typing import F -from pandas.compat.numpy import is_numpy_dev +from pandas.compat.numpy import ( + is_numpy_dev, + np_version_under1p21, +) from pandas.compat.pyarrow import ( pa_version_under1p01, pa_version_under2p0, @@ -148,6 +151,7 @@ def get_lzma_file() -> type[lzma.LZMAFile]: __all__ = [ "is_numpy_dev", + "np_version_under1p21", "pa_version_under1p01", "pa_version_under2p0", "pa_version_under3p0", diff --git a/pandas/compat/numpy/__init__.py b/pandas/compat/numpy/__init__.py index a7cffba501d67..998e9f5cb49a7 100644 --- a/pandas/compat/numpy/__init__.py +++ b/pandas/compat/numpy/__init__.py @@ -6,6 +6,7 @@ # 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") is_numpy_dev = _nlv.dev is not None diff --git a/pandas/tests/extension/base/casting.py b/pandas/tests/extension/base/casting.py index 86dbbe4e6ef10..f66b2d471c2c9 100644 --- a/pandas/tests/extension/base/casting.py +++ b/pandas/tests/extension/base/casting.py @@ -1,6 +1,7 @@ import numpy as np import pytest +from pandas.compat import np_version_under1p21 import pandas.util._test_decorators as td import pandas as pd @@ -30,9 +31,10 @@ 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) - # check that we can compare the dtypes - comp = result.dtypes == df.dtypes - assert not comp.any() + if not np_version_under1p21: + # 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() From 5bc82ad0ec71e3eb112ab00555eb0567d05fea36 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Wed, 20 Jul 2022 08:53:05 -0700 Subject: [PATCH 05/12] fix compat version --- pandas/core/array_algos/putmask.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/core/array_algos/putmask.py b/pandas/core/array_algos/putmask.py index a3249a2465b98..17622e78d1b12 100644 --- a/pandas/core/array_algos/putmask.py +++ b/pandas/core/array_algos/putmask.py @@ -12,6 +12,7 @@ ArrayLike, npt, ) +from pandas.compat import np_version_under1p21 from pandas.core.dtypes.cast import infer_dtype_from from pandas.core.dtypes.common import is_list_like @@ -65,6 +66,9 @@ def putmask_without_repeat( mask : np.ndarray[bool] new : Any """ + if np_version_under1p21: + new = setitem_datetimelike_compat(values, mask.sum(), new) + if getattr(new, "ndim", 0) >= 1: new = new.astype(values.dtype, copy=False) @@ -73,7 +77,7 @@ def putmask_without_repeat( if nlocs > 0 and is_list_like(new) and getattr(new, "ndim", 1) == 1: shape = np.shape(new) # np.shape compat for if setitem_datetimelike_compat - # changed arraylike to list e.g. test_where_dt64_2d + # changed arraylike to list e.g. test_where_dt64_2d if nlocs == shape[-1]: # GH#30567 # If length of ``new`` is less than the length of ``values``, From 58ba04885e0af63627d59d30eb88c4d0fc3dc1b6 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Thu, 28 Jul 2022 16:56:31 -0700 Subject: [PATCH 06/12] xfail Int64 related tests --- pandas/tests/frame/methods/test_quantile.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pandas/tests/frame/methods/test_quantile.py b/pandas/tests/frame/methods/test_quantile.py index 798212f957e3c..66fd8536544b0 100644 --- a/pandas/tests/frame/methods/test_quantile.py +++ b/pandas/tests/frame/methods/test_quantile.py @@ -1,7 +1,10 @@ import numpy as np import pytest -from pandas.compat.numpy import np_percentile_argname +from pandas.compat.numpy import ( + np_percentile_argname, + np_version_under1p21, +) import pandas as pd from pandas import ( @@ -655,6 +658,10 @@ def compute_quantile(self, obj, qs): result = obj.quantile(qs, numeric_only=False) return result + @pytest.mark.xfail( + np_version_under1p21, + reason="failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood", + ) def test_quantile_ea(self, obj, index): # result should be invariant to shuffling @@ -722,6 +729,10 @@ def test_quantile_ea_all_na(self, obj, index): expected = type(obj)(expected) tm.assert_equal(result, expected) + @pytest.mark.xfail( + np_version_under1p21, + reason="failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood", + ) def test_quantile_ea_scalar(self, obj, index): # scalar qs From 3fa99304605f01727725582479f988dab1a4d903 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Fri, 29 Jul 2022 00:51:34 -0700 Subject: [PATCH 07/12] add xfail --- pandas/tests/frame/methods/test_quantile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/tests/frame/methods/test_quantile.py b/pandas/tests/frame/methods/test_quantile.py index 66fd8536544b0..0e581056ab69b 100644 --- a/pandas/tests/frame/methods/test_quantile.py +++ b/pandas/tests/frame/methods/test_quantile.py @@ -707,6 +707,10 @@ def test_quantile_ea_with_na(self, obj, index): # TODO(GH#39763): filtering can be removed after GH#39763 is fixed @pytest.mark.filterwarnings("ignore:Using .astype to convert:FutureWarning") + @pytest.mark.xfail( + np_version_under1p21, + reason="failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood", + ) def test_quantile_ea_all_na(self, obj, index): obj.iloc[:] = index._na_value From 45c0f10e967e07f6d8360d30f8d6da48ae36eeb5 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Fri, 29 Jul 2022 15:45:54 -0700 Subject: [PATCH 08/12] remove xfial --- pandas/tests/frame/methods/test_quantile.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/pandas/tests/frame/methods/test_quantile.py b/pandas/tests/frame/methods/test_quantile.py index 0e581056ab69b..3c106c6441159 100644 --- a/pandas/tests/frame/methods/test_quantile.py +++ b/pandas/tests/frame/methods/test_quantile.py @@ -658,10 +658,6 @@ def compute_quantile(self, obj, qs): result = obj.quantile(qs, numeric_only=False) return result - @pytest.mark.xfail( - np_version_under1p21, - reason="failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood", - ) def test_quantile_ea(self, obj, index): # result should be invariant to shuffling @@ -673,7 +669,7 @@ def test_quantile_ea(self, obj, index): result = self.compute_quantile(obj, qs) exp_dtype = index.dtype - if index.dtype == "Int64": + if not np_version_under1p21 and index.dtype == "Int64": # match non-nullable casting behavior exp_dtype = "Float64" @@ -707,10 +703,6 @@ def test_quantile_ea_with_na(self, obj, index): # TODO(GH#39763): filtering can be removed after GH#39763 is fixed @pytest.mark.filterwarnings("ignore:Using .astype to convert:FutureWarning") - @pytest.mark.xfail( - np_version_under1p21, - reason="failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood", - ) def test_quantile_ea_all_na(self, obj, index): obj.iloc[:] = index._na_value @@ -728,15 +720,11 @@ def test_quantile_ea_all_na(self, obj, index): expected = index.take([-1, -1, -1], allow_fill=True, fill_value=index._na_value) expected = Series(expected, index=qs, name="A") - if expected.dtype == "Int64": + if not np_version_under1p21 and expected.dtype == "Int64": expected = expected.astype("Float64") expected = type(obj)(expected) tm.assert_equal(result, expected) - @pytest.mark.xfail( - np_version_under1p21, - reason="failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood", - ) def test_quantile_ea_scalar(self, obj, index): # scalar qs @@ -749,7 +737,7 @@ def test_quantile_ea_scalar(self, obj, index): result = self.compute_quantile(obj, qs) exp_dtype = index.dtype - if index.dtype == "Int64": + if not np_version_under1p21 and index.dtype == "Int64": exp_dtype = "Float64" expected = Series({"A": index[4]}, dtype=exp_dtype, name=0.5) From a4a25e2682bf99cdf3024f37fa93c742408bae3d Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Sat, 30 Jul 2022 17:40:07 -0700 Subject: [PATCH 09/12] fix xfail --- pandas/tests/frame/methods/test_quantile.py | 30 ++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/pandas/tests/frame/methods/test_quantile.py b/pandas/tests/frame/methods/test_quantile.py index 3c106c6441159..018ea59a71403 100644 --- a/pandas/tests/frame/methods/test_quantile.py +++ b/pandas/tests/frame/methods/test_quantile.py @@ -658,7 +658,7 @@ def compute_quantile(self, obj, qs): result = obj.quantile(qs, numeric_only=False) return result - def test_quantile_ea(self, obj, index): + def test_quantile_ea(self, request, obj, index): # result should be invariant to shuffling indexer = np.arange(len(index), dtype=np.intp) @@ -668,8 +668,14 @@ def test_quantile_ea(self, obj, index): qs = [0.5, 0, 1] result = self.compute_quantile(obj, qs) + if np_version_under1p21 and index.dtype == "timedelta64[ns]": + mark = pytest.mark.xfail( + reason="failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood" + ) + request.node.add_marker(mark) + exp_dtype = index.dtype - if not np_version_under1p21 and index.dtype == "Int64": + if index.dtype == "Int64": # match non-nullable casting behavior exp_dtype = "Float64" @@ -703,7 +709,7 @@ def test_quantile_ea_with_na(self, obj, index): # TODO(GH#39763): filtering can be removed after GH#39763 is fixed @pytest.mark.filterwarnings("ignore:Using .astype to convert:FutureWarning") - def test_quantile_ea_all_na(self, obj, index): + def test_quantile_ea_all_na(self, request, obj, index): obj.iloc[:] = index._na_value # TODO(ArrayManager): this casting should be unnecessary after GH#39763 is fixed @@ -718,14 +724,20 @@ def test_quantile_ea_all_na(self, obj, index): qs = [0.5, 0, 1] result = self.compute_quantile(obj, qs) + if np_version_under1p21 and index.dtype == "timedelta64[ns]": + mark = pytest.mark.xfail( + reason="failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood" + ) + request.node.add_marker(mark) + expected = index.take([-1, -1, -1], allow_fill=True, fill_value=index._na_value) expected = Series(expected, index=qs, name="A") - if not np_version_under1p21 and expected.dtype == "Int64": + if expected.dtype == "Int64": expected = expected.astype("Float64") expected = type(obj)(expected) tm.assert_equal(result, expected) - def test_quantile_ea_scalar(self, obj, index): + def test_quantile_ea_scalar(self, request, obj, index): # scalar qs # result should be invariant to shuffling @@ -736,8 +748,14 @@ def test_quantile_ea_scalar(self, obj, index): qs = 0.5 result = self.compute_quantile(obj, qs) + if np_version_under1p21 and index.dtype == "timedelta64[ns]": + mark = pytest.mark.xfail( + reason="failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood" + ) + request.node.add_marker(mark) + exp_dtype = index.dtype - if not np_version_under1p21 and index.dtype == "Int64": + if index.dtype == "Int64": exp_dtype = "Float64" expected = Series({"A": index[4]}, dtype=exp_dtype, name=0.5) From 1ee85ed7700f878575519b61895aca682b58aacf Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Sat, 30 Jul 2022 17:43:35 -0700 Subject: [PATCH 10/12] fix line len --- pandas/tests/frame/methods/test_quantile.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pandas/tests/frame/methods/test_quantile.py b/pandas/tests/frame/methods/test_quantile.py index 018ea59a71403..a3e8327d5ee21 100644 --- a/pandas/tests/frame/methods/test_quantile.py +++ b/pandas/tests/frame/methods/test_quantile.py @@ -669,9 +669,8 @@ def test_quantile_ea(self, request, obj, index): result = self.compute_quantile(obj, qs) if np_version_under1p21 and index.dtype == "timedelta64[ns]": - mark = pytest.mark.xfail( - reason="failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood" - ) + msg = "failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood" + mark = pytest.mark.xfail(reason=msg) request.node.add_marker(mark) exp_dtype = index.dtype @@ -725,9 +724,8 @@ def test_quantile_ea_all_na(self, request, obj, index): result = self.compute_quantile(obj, qs) if np_version_under1p21 and index.dtype == "timedelta64[ns]": - mark = pytest.mark.xfail( - reason="failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood" - ) + msg = "failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood" + mark = pytest.mark.xfail(reason=msg) request.node.add_marker(mark) expected = index.take([-1, -1, -1], allow_fill=True, fill_value=index._na_value) @@ -749,9 +747,8 @@ def test_quantile_ea_scalar(self, request, obj, index): result = self.compute_quantile(obj, qs) if np_version_under1p21 and index.dtype == "timedelta64[ns]": - mark = pytest.mark.xfail( - reason="failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood" - ) + msg = "failed on Numpy 1.20.3; TypeError: data type 'Int64' not understood" + mark = pytest.mark.xfail(reason=msg) request.node.add_marker(mark) exp_dtype = index.dtype From 78fcfa31e17d1e721b3afee87beeafad86c98bdf Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Sat, 30 Jul 2022 19:38:39 -0700 Subject: [PATCH 11/12] remove the last compat --- pandas/compat/numpy/__init__.py | 1 - pandas/tests/indexing/test_iloc.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/pandas/compat/numpy/__init__.py b/pandas/compat/numpy/__init__.py index 998e9f5cb49a7..60ec74553a207 100644 --- a/pandas/compat/numpy/__init__.py +++ b/pandas/compat/numpy/__init__.py @@ -11,7 +11,6 @@ np_version_gte1p22 = _nlv >= Version("1.22") is_numpy_dev = _nlv.dev is not None _min_numpy_ver = "1.20.3" -is_numpy_min = _nlv == Version(_min_numpy_ver) if is_numpy_dev or not np_version_under1p22: np_percentile_argname = "method" diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index 2a116c992231b..fdf741040407f 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -10,7 +10,6 @@ import numpy as np import pytest -from pandas.compat.numpy import is_numpy_min from pandas.errors import IndexingError import pandas.util._test_decorators as td @@ -1199,7 +1198,6 @@ def test_iloc_getitem_int_single_ea_block_view(self): arr[2] = arr[-1] assert ser[0] == arr[-1] - @pytest.mark.xfail(is_numpy_min, reason="Column A gets coerced to integer type") def test_iloc_setitem_multicolumn_to_datetime(self, using_array_manager): # GH#20511 From 8968f09f9609e23db2d30bf66da1a968d3a032c1 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Mon, 1 Aug 2022 13:02:50 -0700 Subject: [PATCH 12/12] add comment back, add error type in xfail --- pandas/tests/extension/base/casting.py | 1 + pandas/tests/frame/methods/test_quantile.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/tests/extension/base/casting.py b/pandas/tests/extension/base/casting.py index f66b2d471c2c9..0eb8123e6bdb8 100644 --- a/pandas/tests/extension/base/casting.py +++ b/pandas/tests/extension/base/casting.py @@ -31,6 +31,7 @@ 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 diff --git a/pandas/tests/frame/methods/test_quantile.py b/pandas/tests/frame/methods/test_quantile.py index a3e8327d5ee21..16b82727fd069 100644 --- a/pandas/tests/frame/methods/test_quantile.py +++ b/pandas/tests/frame/methods/test_quantile.py @@ -670,7 +670,7 @@ def test_quantile_ea(self, request, obj, index): 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) + mark = pytest.mark.xfail(reason=msg, raises=TypeError) request.node.add_marker(mark) exp_dtype = index.dtype @@ -725,7 +725,7 @@ def test_quantile_ea_all_na(self, request, obj, index): 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) + mark = pytest.mark.xfail(reason=msg, raises=TypeError) request.node.add_marker(mark) expected = index.take([-1, -1, -1], allow_fill=True, fill_value=index._na_value) @@ -748,7 +748,7 @@ def test_quantile_ea_scalar(self, request, obj, index): 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) + mark = pytest.mark.xfail(reason=msg, raises=TypeError) request.node.add_marker(mark) exp_dtype = index.dtype