From 3b105fff215122fdb80c52c3be99f310a73844b7 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <> Date: Thu, 8 Dec 2022 14:58:12 +0000 Subject: [PATCH 1/3] numpy compat --- pandas/tests/dtypes/test_missing.py | 9 ++++++++- pandas/tests/frame/methods/test_compare.py | 14 ++++++++++++-- pandas/tests/indexes/object/test_indexing.py | 6 ++++++ pandas/tests/series/methods/test_equals.py | 5 +++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index eeddf443dba86..68e8416ff23b6 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -3,6 +3,7 @@ from decimal import Decimal import numpy as np +from pkg_resources import parse_version import pytest from pandas._config import config as cf @@ -460,7 +461,13 @@ 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 ( + parse_version(np.__version__) > parse_version("1.24") + and "dev" in np.__version__ + ) + ) else nullcontext() ) with cm: diff --git a/pandas/tests/frame/methods/test_compare.py b/pandas/tests/frame/methods/test_compare.py index 2c47285d7c507..3d333aaa8f463 100644 --- a/pandas/tests/frame/methods/test_compare.py +++ b/pandas/tests/frame/methods/test_compare.py @@ -1,4 +1,5 @@ import numpy as np +from pkg_resources import parse_version import pytest import pandas as pd @@ -257,8 +258,17 @@ 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 parse_version(np.__version__) > parse_version("1.24.0") + and "dev" in np.__version__ + ): + # 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..76177ab6222d0 100644 --- a/pandas/tests/indexes/object/test_indexing.py +++ b/pandas/tests/indexes/object/test_indexing.py @@ -1,6 +1,7 @@ from decimal import Decimal import numpy as np +from pkg_resources import parse_version import pytest from pandas._libs.missing import is_matching_na @@ -92,6 +93,11 @@ def test_get_indexer_non_unique_nas(self, nulls_fixture): tm.assert_numpy_array_equal(indexer, expected_indexer) tm.assert_numpy_array_equal(missing, expected_missing) + @pytest.mark.skipif( + parse_version(np.__version__) > parse_version("1.24.0") + and "dev" in np.__version__, + reason="GH50124", + ) @pytest.mark.filterwarnings("ignore:elementwise comp:DeprecationWarning") def test_get_indexer_non_unique_np_nats(self, np_nat_fixture, np_nat_fixture2): expected_missing = np.array([], dtype=np.intp) diff --git a/pandas/tests/series/methods/test_equals.py b/pandas/tests/series/methods/test_equals.py index 22e27c271df88..c25e46d686cd3 100644 --- a/pandas/tests/series/methods/test_equals.py +++ b/pandas/tests/series/methods/test_equals.py @@ -2,6 +2,7 @@ import copy import numpy as np +from pkg_resources import parse_version import pytest from pandas._libs.missing import is_matching_na @@ -51,6 +52,10 @@ def test_equals_list_array(val): cm = ( tm.assert_produces_warning(FutureWarning, check_stacklevel=False) if isinstance(val, str) + and not ( + parse_version(np.__version__) > parse_version("1.24.0") + and "dev" in np.__version__ + ) else nullcontext() ) with cm: From c7a1ed2339400e5fe7fd1b98db36302c76f6641f Mon Sep 17 00:00:00 2001 From: MarcoGorelli <> Date: Thu, 8 Dec 2022 15:53:51 +0000 Subject: [PATCH 2/3] use is_numpy_dev --- pandas/tests/dtypes/test_missing.py | 10 ++-------- pandas/tests/frame/methods/test_compare.py | 9 +++------ pandas/tests/indexes/object/test_indexing.py | 8 ++------ pandas/tests/series/methods/test_equals.py | 8 ++------ 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index 68e8416ff23b6..94707dc2e68c5 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -3,13 +3,13 @@ from decimal import Decimal import numpy as np -from pkg_resources import parse_version import pytest from pandas._config import config as cf 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, @@ -461,13 +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) - and not ( - parse_version(np.__version__) > parse_version("1.24") - and "dev" in np.__version__ - ) - ) + 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 3d333aaa8f463..455acde1af684 100644 --- a/pandas/tests/frame/methods/test_compare.py +++ b/pandas/tests/frame/methods/test_compare.py @@ -1,7 +1,8 @@ import numpy as np -from pkg_resources import parse_version import pytest +from pandas.compat import is_numpy_dev + import pandas as pd import pandas._testing as tm @@ -258,11 +259,7 @@ def test_compare_ea_and_np_dtype(val1, val2): ("b", "other"): np.nan, } ) - if ( - val1 is pd.NA - and parse_version(np.__version__) > parse_version("1.24.0") - and "dev" in np.__version__ - ): + 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) diff --git a/pandas/tests/indexes/object/test_indexing.py b/pandas/tests/indexes/object/test_indexing.py index 76177ab6222d0..0e292c506e2a9 100644 --- a/pandas/tests/indexes/object/test_indexing.py +++ b/pandas/tests/indexes/object/test_indexing.py @@ -1,10 +1,10 @@ from decimal import Decimal import numpy as np -from pkg_resources import parse_version import pytest from pandas._libs.missing import is_matching_na +from pandas.compat import is_numpy_dev import pandas as pd from pandas import Index @@ -93,11 +93,7 @@ def test_get_indexer_non_unique_nas(self, nulls_fixture): tm.assert_numpy_array_equal(indexer, expected_indexer) tm.assert_numpy_array_equal(missing, expected_missing) - @pytest.mark.skipif( - parse_version(np.__version__) > parse_version("1.24.0") - and "dev" in np.__version__, - reason="GH50124", - ) + @pytest.mark.skipif(is_numpy_dev, reason="GH50124") @pytest.mark.filterwarnings("ignore:elementwise comp:DeprecationWarning") def test_get_indexer_non_unique_np_nats(self, np_nat_fixture, np_nat_fixture2): expected_missing = np.array([], dtype=np.intp) diff --git a/pandas/tests/series/methods/test_equals.py b/pandas/tests/series/methods/test_equals.py index c25e46d686cd3..9278d1b51e1aa 100644 --- a/pandas/tests/series/methods/test_equals.py +++ b/pandas/tests/series/methods/test_equals.py @@ -2,10 +2,10 @@ import copy import numpy as np -from pkg_resources import parse_version 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 @@ -51,11 +51,7 @@ def test_equals_list_array(val): cm = ( tm.assert_produces_warning(FutureWarning, check_stacklevel=False) - if isinstance(val, str) - and not ( - parse_version(np.__version__) > parse_version("1.24.0") - and "dev" in np.__version__ - ) + if isinstance(val, str) and not is_numpy_dev else nullcontext() ) with cm: From 429b25ce4894adcc87954b22b7020245ffc0dc97 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <> Date: Thu, 8 Dec 2022 18:53:03 +0000 Subject: [PATCH 3/3] dont skip test --- pandas/tests/indexes/object/test_indexing.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pandas/tests/indexes/object/test_indexing.py b/pandas/tests/indexes/object/test_indexing.py index 0e292c506e2a9..87d3afc77d556 100644 --- a/pandas/tests/indexes/object/test_indexing.py +++ b/pandas/tests/indexes/object/test_indexing.py @@ -4,7 +4,6 @@ import pytest from pandas._libs.missing import is_matching_na -from pandas.compat import is_numpy_dev import pandas as pd from pandas import Index @@ -93,7 +92,6 @@ def test_get_indexer_non_unique_nas(self, nulls_fixture): tm.assert_numpy_array_equal(indexer, expected_indexer) tm.assert_numpy_array_equal(missing, expected_missing) - @pytest.mark.skipif(is_numpy_dev, reason="GH50124") @pytest.mark.filterwarnings("ignore:elementwise comp:DeprecationWarning") def test_get_indexer_non_unique_np_nats(self, np_nat_fixture, np_nat_fixture2): expected_missing = np.array([], dtype=np.intp) @@ -116,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( [