From dcdf2f1904433ff859b24cc88b5def011807809b Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Fri, 7 Feb 2020 16:08:07 -0800 Subject: [PATCH 1/3] Added pd.NA to nulls_fixture --- pandas/conftest.py | 2 +- pandas/tests/arithmetic/test_interval.py | 8 ++++++++ pandas/tests/indexes/multi/test_indexing.py | 4 ++++ pandas/tests/indexes/test_base.py | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 131a011c5a101..cbcc18bf87766 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -441,7 +441,7 @@ def other_closed(request): return request.param -@pytest.fixture(params=[None, np.nan, pd.NaT, float("nan"), np.float("NaN")]) +@pytest.fixture(params=[None, np.nan, pd.NaT, float("nan"), np.float("NaN"), pd.NA]) def nulls_fixture(request): """ Fixture for each null type in pandas. diff --git a/pandas/tests/arithmetic/test_interval.py b/pandas/tests/arithmetic/test_interval.py index f9e1a515277d5..fc595681fe556 100644 --- a/pandas/tests/arithmetic/test_interval.py +++ b/pandas/tests/arithmetic/test_interval.py @@ -129,6 +129,10 @@ def test_compare_scalar_interval_mixed_closed(self, op, closed, other_closed): def test_compare_scalar_na(self, op, array, nulls_fixture): result = op(array, nulls_fixture) expected = self.elementwise_comparison(op, array, nulls_fixture) + + if nulls_fixture is pd.NA: + pytest.xfail("assert_numpy_array_equal broken for pd.NA") + tm.assert_numpy_array_equal(result, expected) @pytest.mark.parametrize( @@ -207,6 +211,10 @@ def test_compare_list_like_nan(self, op, array, nulls_fixture): other = [nulls_fixture] * 4 result = op(array, other) expected = self.elementwise_comparison(op, array, other) + + if nulls_fixture is pd.NA: + pytest.xfail("assert_numpy_array_equal broken for pd.NA") + tm.assert_numpy_array_equal(result, expected) @pytest.mark.parametrize( diff --git a/pandas/tests/indexes/multi/test_indexing.py b/pandas/tests/indexes/multi/test_indexing.py index 21a4773fa3683..7daf783ae9249 100644 --- a/pandas/tests/indexes/multi/test_indexing.py +++ b/pandas/tests/indexes/multi/test_indexing.py @@ -384,6 +384,10 @@ def test_get_loc_nan(level, nulls_fixture): key = ["b", "d"] levels[level] = np.array([0, nulls_fixture], dtype=type(nulls_fixture)) key[level] = nulls_fixture + + if nulls_fixture is pd.NA: + pytest.xfail("MultiIndex from pd.NA broken") + idx = MultiIndex.from_product(levels) assert idx.get_loc(tuple(key)) == 3 diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 04af9b09bbf89..f93d2bc2dda43 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -305,6 +305,9 @@ def test_index_ctor_infer_nat_dt_like(self, pos, klass, dtype, ctor, nulls_fixtu data = [ctor] data.insert(pos, nulls_fixture) + if nulls_fixture is pd.NA: + pytest.xfail("Broken with pd.NA?") + result = Index(data) tm.assert_index_equal(result, expected) @@ -1964,6 +1967,9 @@ def test_isin_nan_common_float64(self, nulls_fixture): pytest.skip("pd.NaT not compatible with Float64Index") # Float64Index overrides isin, so must be checked separately + if nulls_fixture is pd.NA: + pytest.xfail("Not sure how to handle with Float64Index?") + tm.assert_numpy_array_equal( Float64Index([1.0, nulls_fixture]).isin([np.nan]), np.array([False, True]) ) From bd0e031ce7e35364d2b934ef6c5786671f123efe Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Tue, 11 Feb 2020 08:31:21 -0800 Subject: [PATCH 2/3] Updated error messages --- pandas/tests/arithmetic/test_interval.py | 6 +++--- pandas/tests/indexes/multi/test_indexing.py | 2 +- pandas/tests/indexes/test_base.py | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pandas/tests/arithmetic/test_interval.py b/pandas/tests/arithmetic/test_interval.py index fc595681fe556..a8c23d23938d1 100644 --- a/pandas/tests/arithmetic/test_interval.py +++ b/pandas/tests/arithmetic/test_interval.py @@ -130,8 +130,8 @@ def test_compare_scalar_na(self, op, array, nulls_fixture): result = op(array, nulls_fixture) expected = self.elementwise_comparison(op, array, nulls_fixture) - if nulls_fixture is pd.NA: - pytest.xfail("assert_numpy_array_equal broken for pd.NA") + if nulls_fixture is pd.NA and array.dtype != pd.IntervalDtype("int"): + pytest.xfail("broken for non-integer IntervalArray; see GH 31881") tm.assert_numpy_array_equal(result, expected) @@ -213,7 +213,7 @@ def test_compare_list_like_nan(self, op, array, nulls_fixture): expected = self.elementwise_comparison(op, array, other) if nulls_fixture is pd.NA: - pytest.xfail("assert_numpy_array_equal broken for pd.NA") + pytest.xfail("broken for non-integer IntervalArray; see GH 31881") tm.assert_numpy_array_equal(result, expected) diff --git a/pandas/tests/indexes/multi/test_indexing.py b/pandas/tests/indexes/multi/test_indexing.py index 7daf783ae9249..3c9b34a4a1439 100644 --- a/pandas/tests/indexes/multi/test_indexing.py +++ b/pandas/tests/indexes/multi/test_indexing.py @@ -386,7 +386,7 @@ def test_get_loc_nan(level, nulls_fixture): key[level] = nulls_fixture if nulls_fixture is pd.NA: - pytest.xfail("MultiIndex from pd.NA broken") + pytest.xfail("MultiIndex from pd.NA in np.array broken; see GH 31883") idx = MultiIndex.from_product(levels) assert idx.get_loc(tuple(key)) == 3 diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index f93d2bc2dda43..f8cb697fd909d 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -306,7 +306,8 @@ def test_index_ctor_infer_nat_dt_like(self, pos, klass, dtype, ctor, nulls_fixtu data.insert(pos, nulls_fixture) if nulls_fixture is pd.NA: - pytest.xfail("Broken with pd.NA?") + expected = Index([pd.NA, pd.NaT]) + pytest.xfail("Broken with np.NaT ctor; see GH 31884") result = Index(data) tm.assert_index_equal(result, expected) @@ -1968,7 +1969,7 @@ def test_isin_nan_common_float64(self, nulls_fixture): # Float64Index overrides isin, so must be checked separately if nulls_fixture is pd.NA: - pytest.xfail("Not sure how to handle with Float64Index?") + pytest.xfail("Float64Index cannot contain pd.NA") tm.assert_numpy_array_equal( Float64Index([1.0, nulls_fixture]).isin([np.nan]), np.array([False, True]) From 594c26f5c4e92320afa4aa14e62d112e83959d67 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 19 Feb 2020 22:52:00 -0500 Subject: [PATCH 3/3] updated gh issue --- pandas/tests/arithmetic/test_interval.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/arithmetic/test_interval.py b/pandas/tests/arithmetic/test_interval.py index a8c23d23938d1..3f85ac8c190db 100644 --- a/pandas/tests/arithmetic/test_interval.py +++ b/pandas/tests/arithmetic/test_interval.py @@ -131,7 +131,7 @@ def test_compare_scalar_na(self, op, array, nulls_fixture): expected = self.elementwise_comparison(op, array, nulls_fixture) if nulls_fixture is pd.NA and array.dtype != pd.IntervalDtype("int"): - pytest.xfail("broken for non-integer IntervalArray; see GH 31881") + pytest.xfail("broken for non-integer IntervalArray; see GH 31882") tm.assert_numpy_array_equal(result, expected) @@ -213,7 +213,7 @@ def test_compare_list_like_nan(self, op, array, nulls_fixture): expected = self.elementwise_comparison(op, array, other) if nulls_fixture is pd.NA: - pytest.xfail("broken for non-integer IntervalArray; see GH 31881") + pytest.xfail("broken for non-integer IntervalArray; see GH 31882") tm.assert_numpy_array_equal(result, expected)