diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index eeddf443dba86..94707dc2e68c5 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -9,6 +9,7 @@ from pandas._libs import missing as libmissing from pandas._libs.tslibs import iNaT +from pandas.compat import is_numpy_dev from pandas.core.dtypes.common import ( is_float, @@ -460,7 +461,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) + if isinstance(val, str) and not is_numpy_dev else nullcontext() ) with cm: diff --git a/pandas/tests/frame/methods/test_compare.py b/pandas/tests/frame/methods/test_compare.py index 2c47285d7c507..455acde1af684 100644 --- a/pandas/tests/frame/methods/test_compare.py +++ b/pandas/tests/frame/methods/test_compare.py @@ -1,6 +1,8 @@ import numpy as np import pytest +from pandas.compat import is_numpy_dev + import pandas as pd import pandas._testing as tm @@ -257,8 +259,13 @@ def test_compare_ea_and_np_dtype(val1, val2): ("b", "other"): np.nan, } ) - result = df1.compare(df2, keep_shape=True) - tm.assert_frame_equal(result, expected) + if val1 is pd.NA and is_numpy_dev: + # 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) + else: + result = df1.compare(df2, keep_shape=True) + tm.assert_frame_equal(result, expected) @pytest.mark.parametrize( diff --git a/pandas/tests/indexes/object/test_indexing.py b/pandas/tests/indexes/object/test_indexing.py index a33173dc83569..87d3afc77d556 100644 --- a/pandas/tests/indexes/object/test_indexing.py +++ b/pandas/tests/indexes/object/test_indexing.py @@ -114,6 +114,13 @@ def test_get_indexer_non_unique_np_nats(self, np_nat_fixture, np_nat_fixture2): tm.assert_numpy_array_equal(missing, expected_missing) # dt64nat vs td64nat else: + try: + np_nat_fixture == np_nat_fixture2 + except (TypeError, OverflowError): + # Numpy will raise on uncomparable types, like + # np.datetime64('NaT', 'Y') and np.datetime64('NaT', 'ps') + # https://github.com/numpy/numpy/issues/22762 + return index = Index( np.array( [ diff --git a/pandas/tests/series/methods/test_equals.py b/pandas/tests/series/methods/test_equals.py index 22e27c271df88..9278d1b51e1aa 100644 --- a/pandas/tests/series/methods/test_equals.py +++ b/pandas/tests/series/methods/test_equals.py @@ -5,6 +5,7 @@ import pytest from pandas._libs.missing import is_matching_na +from pandas.compat import is_numpy_dev from pandas.core.dtypes.common import is_float @@ -50,7 +51,7 @@ def test_equals_list_array(val): cm = ( tm.assert_produces_warning(FutureWarning, check_stacklevel=False) - if isinstance(val, str) + if isinstance(val, str) and not is_numpy_dev else nullcontext() ) with cm: