From 475aead6cbeb65c55cdf5f4ab3159dd1390feaf1 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Sun, 18 Jun 2023 09:34:48 -0700 Subject: [PATCH] CI: Adjust tests for release of numpy 1.25 --- pandas/compat/numpy/__init__.py | 1 + pandas/tests/apply/test_frame_apply_relabeling.py | 4 ++-- pandas/tests/dtypes/test_missing.py | 4 ++-- pandas/tests/frame/methods/test_compare.py | 4 ++-- pandas/tests/frame/test_unary.py | 4 ++-- pandas/tests/series/methods/test_describe.py | 4 ++-- pandas/tests/series/methods/test_equals.py | 4 ++-- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pandas/compat/numpy/__init__.py b/pandas/compat/numpy/__init__.py index 97c434d8f35d0..d5dad2b8dc4bd 100644 --- a/pandas/compat/numpy/__init__.py +++ b/pandas/compat/numpy/__init__.py @@ -9,6 +9,7 @@ np_version_under1p22 = _nlv < Version("1.22") np_version_gte1p24 = _nlv >= Version("1.24") np_version_gte1p24p3 = _nlv >= Version("1.24.3") +np_version_gte1p25 = _nlv >= Version("1.25") is_numpy_dev = _nlv.dev is not None _min_numpy_ver = "1.21.6" diff --git a/pandas/tests/apply/test_frame_apply_relabeling.py b/pandas/tests/apply/test_frame_apply_relabeling.py index 2dcd228cdc19c..2652d43fd42ec 100644 --- a/pandas/tests/apply/test_frame_apply_relabeling.py +++ b/pandas/tests/apply/test_frame_apply_relabeling.py @@ -1,7 +1,7 @@ import numpy as np import pytest -from pandas.compat import is_numpy_dev +from pandas.compat.numpy import np_version_gte1p25 import pandas as pd import pandas._testing as tm @@ -45,7 +45,7 @@ def test_agg_relabel_multi_columns_multi_methods(): tm.assert_frame_equal(result, expected) -@pytest.mark.xfail(is_numpy_dev, reason="name of min now equals name of np.min") +@pytest.mark.xfail(np_version_gte1p25, reason="name of min now equals name of np.min") def test_agg_relabel_partial_functions(): # GH 26513, test on partial, functools or more complex cases df = pd.DataFrame({"A": [1, 2, 1, 2], "B": [1, 2, 3, 4], "C": [3, 4, 5, 6]}) diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index bd8dffd2abe1f..1c275098adeb9 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -9,7 +9,7 @@ from pandas._libs import missing as libmissing from pandas._libs.tslibs import iNaT -from pandas.compat import is_numpy_dev +from pandas.compat.numpy import np_version_gte1p25 from pandas.core.dtypes.common import ( is_float, @@ -468,7 +468,7 @@ def test_array_equivalent_series(val): cm = ( # stacklevel is chosen to make sense when called from .equals tm.assert_produces_warning(FutureWarning, match=msg, check_stacklevel=False) - if isinstance(val, str) and not is_numpy_dev + if isinstance(val, str) and not np_version_gte1p25 else nullcontext() ) with cm: diff --git a/pandas/tests/frame/methods/test_compare.py b/pandas/tests/frame/methods/test_compare.py index 6369a624bce71..a4d0a7068a3a6 100644 --- a/pandas/tests/frame/methods/test_compare.py +++ b/pandas/tests/frame/methods/test_compare.py @@ -1,7 +1,7 @@ import numpy as np import pytest -from pandas.compat import is_numpy_dev +from pandas.compat.numpy import np_version_gte1p25 import pandas as pd import pandas._testing as tm @@ -269,7 +269,7 @@ def test_compare_ea_and_np_dtype(val1, val2): # GH#18463 TODO: is this really the desired behavior? expected.loc[1, ("a", "self")] = np.nan - if val1 is pd.NA and is_numpy_dev: + if val1 is pd.NA and np_version_gte1p25: # can't compare with numpy array if it contains pd.NA with pytest.raises(TypeError, match="boolean value of NA is ambiguous"): result = df1.compare(df2, keep_shape=True) diff --git a/pandas/tests/frame/test_unary.py b/pandas/tests/frame/test_unary.py index 07bcb2ccc121a..5e29d3c868983 100644 --- a/pandas/tests/frame/test_unary.py +++ b/pandas/tests/frame/test_unary.py @@ -3,7 +3,7 @@ import numpy as np import pytest -from pandas.compat import is_numpy_dev +from pandas.compat.numpy import np_version_gte1p25 import pandas as pd import pandas._testing as tm @@ -130,7 +130,7 @@ def test_pos_object(self, df): ) def test_pos_object_raises(self, df): # GH#21380 - if is_numpy_dev: + if np_version_gte1p25: with pytest.raises( TypeError, match=r"^bad operand type for unary \+: \'str\'$" ): diff --git a/pandas/tests/series/methods/test_describe.py b/pandas/tests/series/methods/test_describe.py index 0062d45cc68a0..7f706fc54897e 100644 --- a/pandas/tests/series/methods/test_describe.py +++ b/pandas/tests/series/methods/test_describe.py @@ -1,7 +1,7 @@ import numpy as np import pytest -from pandas.compat import is_numpy_dev +from pandas.compat.numpy import np_version_gte1p25 from pandas.core.dtypes.common import ( is_complex_dtype, @@ -166,7 +166,7 @@ def test_numeric_result_dtype(self, any_numeric_dtype): dtype = "complex128" if is_complex_dtype(any_numeric_dtype) else None ser = Series([0, 1], dtype=any_numeric_dtype) - if dtype == "complex128" and is_numpy_dev: + if dtype == "complex128" and np_version_gte1p25: with pytest.raises( TypeError, match=r"^a must be an array of real numbers$" ): diff --git a/pandas/tests/series/methods/test_equals.py b/pandas/tests/series/methods/test_equals.py index 9278d1b51e1aa..b94723b7cbddf 100644 --- a/pandas/tests/series/methods/test_equals.py +++ b/pandas/tests/series/methods/test_equals.py @@ -5,7 +5,7 @@ import pytest from pandas._libs.missing import is_matching_na -from pandas.compat import is_numpy_dev +from pandas.compat.numpy import np_version_gte1p25 from pandas.core.dtypes.common import is_float @@ -51,7 +51,7 @@ def test_equals_list_array(val): cm = ( tm.assert_produces_warning(FutureWarning, check_stacklevel=False) - if isinstance(val, str) and not is_numpy_dev + if isinstance(val, str) and not np_version_gte1p25 else nullcontext() ) with cm: