From 58caea969c6fdfd9b1c4e252c3ea1be988eb75c1 Mon Sep 17 00:00:00 2001 From: rhshadrach Date: Sun, 3 Jan 2021 16:05:00 -0500 Subject: [PATCH 1/2] TST: Replace pytest.xfail --- pandas/tests/indexes/test_common.py | 4 ++-- pandas/tests/indexes/test_setops.py | 2 +- pandas/tests/series/indexing/test_setitem.py | 11 ++++++----- pandas/tests/series/indexing/test_where.py | 6 +----- pandas/tests/series/test_arithmetic.py | 12 +++++++++--- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/pandas/tests/indexes/test_common.py b/pandas/tests/indexes/test_common.py index bc1295cc0a0ce..8b317af9680f3 100644 --- a/pandas/tests/indexes/test_common.py +++ b/pandas/tests/indexes/test_common.py @@ -388,7 +388,7 @@ def test_asi8_deprecation(self, index): @pytest.mark.parametrize("na_position", [None, "middle"]) def test_sort_values_invalid_na_position(index_with_missing, na_position): if isinstance(index_with_missing, (CategoricalIndex, MultiIndex)): - pytest.xfail("missing value sorting order not defined for index type") + pytest.skip("missing value sorting order not defined for index type") if na_position not in ["first", "last"]: with pytest.raises(ValueError, match=f"invalid na_position: {na_position}"): @@ -401,7 +401,7 @@ def test_sort_values_with_missing(index_with_missing, na_position): # sort non-missing and place missing according to na_position if isinstance(index_with_missing, (CategoricalIndex, MultiIndex)): - pytest.xfail("missing value sorting order not defined for index type") + pytest.skip("missing value sorting order not defined for index type") missing_count = np.sum(index_with_missing.isna()) not_na_vals = index_with_missing[index_with_missing.notna()].values diff --git a/pandas/tests/indexes/test_setops.py b/pandas/tests/indexes/test_setops.py index 64b08c6058b81..f2a33df71e8e3 100644 --- a/pandas/tests/indexes/test_setops.py +++ b/pandas/tests/indexes/test_setops.py @@ -49,7 +49,7 @@ def test_union_different_types(request, index, index_fixture2): ) if any(isinstance(idx, pd.MultiIndex) for idx in (idx1, idx2)): - pytest.xfail("This test doesn't consider multiindixes.") + pytest.skip("This test doesn't consider multiindixes.") if is_dtype_equal(idx1.dtype, idx2.dtype): pytest.skip("This test only considers non matching dtypes.") diff --git a/pandas/tests/series/indexing/test_setitem.py b/pandas/tests/series/indexing/test_setitem.py index d6d0723bee0e8..f79a822481ea0 100644 --- a/pandas/tests/series/indexing/test_setitem.py +++ b/pandas/tests/series/indexing/test_setitem.py @@ -328,14 +328,15 @@ def test_series_where(self, obj, key, expected): tm.assert_series_equal(res, expected) def test_index_where(self, obj, key, expected, request): - if obj.dtype == bool: - msg = "Index/Series casting behavior inconsistent GH#38692" - mark = pytest.xfail(reason=msg) - request.node.add_marker(mark) - mask = np.zeros(obj.shape, dtype=bool) mask[key] = True + if obj.dtype == bool and not mask.all(): + # When mask is all True, casting behavior does not apply + msg = "Index/Series casting behavior inconsistent GH#38692" + mark = pytest.mark.xfail(reason=msg) + request.node.add_marker(mark) + res = Index(obj).where(~mask, np.nan) tm.assert_index_equal(res, Index(expected)) diff --git a/pandas/tests/series/indexing/test_where.py b/pandas/tests/series/indexing/test_where.py index 59c68fba53e25..edcec386cd8ba 100644 --- a/pandas/tests/series/indexing/test_where.py +++ b/pandas/tests/series/indexing/test_where.py @@ -489,10 +489,6 @@ def test_where_datetimelike_categorical(tz_naive_fixture): tm.assert_series_equal(res, Series(dr)) # DataFrame.where - if tz is None: - res = pd.DataFrame(lvals).where(mask[:, None], pd.DataFrame(rvals)) - else: - with pytest.xfail(reason="frame._values loses tz"): - res = pd.DataFrame(lvals).where(mask[:, None], pd.DataFrame(rvals)) + res = pd.DataFrame(lvals).where(mask[:, None], pd.DataFrame(rvals)) tm.assert_frame_equal(res, pd.DataFrame(dr)) diff --git a/pandas/tests/series/test_arithmetic.py b/pandas/tests/series/test_arithmetic.py index a0e0213a6dce5..219aaddb116cd 100644 --- a/pandas/tests/series/test_arithmetic.py +++ b/pandas/tests/series/test_arithmetic.py @@ -737,12 +737,18 @@ def test_align_date_objects_with_datetimeindex(self): class TestNamePreservation: @pytest.mark.parametrize("box", [list, tuple, np.array, Index, Series, pd.array]) @pytest.mark.parametrize("flex", [True, False]) - def test_series_ops_name_retention(self, flex, box, names, all_binary_operators): + def test_series_ops_name_retention( + self, request, flex, box, names, all_binary_operators + ): # GH#33930 consistent name renteiton op = all_binary_operators - if op is ops.rfloordiv and box in [list, tuple]: - pytest.xfail("op fails because of inconsistent ndarray-wrapping GH#28759") + if op is ops.rfloordiv and box in [list, tuple] and not flex: + request.node.add_marker( + pytest.mark.xfail( + reason="op fails because of inconsistent ndarray-wrapping GH#28759" + ) + ) left = Series(range(10), name=names[0]) right = Series(range(10), name=names[1]) From 43e3ac96c32486e83aefd966b52cb3e94c1ff475 Mon Sep 17 00:00:00 2001 From: rhshadrach Date: Sun, 3 Jan 2021 16:32:03 -0500 Subject: [PATCH 2/2] Partially revert replacing xfail with skip --- pandas/tests/indexes/test_common.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pandas/tests/indexes/test_common.py b/pandas/tests/indexes/test_common.py index 8b317af9680f3..2548fc18e4032 100644 --- a/pandas/tests/indexes/test_common.py +++ b/pandas/tests/indexes/test_common.py @@ -386,9 +386,13 @@ def test_asi8_deprecation(self, index): @pytest.mark.parametrize("na_position", [None, "middle"]) -def test_sort_values_invalid_na_position(index_with_missing, na_position): - if isinstance(index_with_missing, (CategoricalIndex, MultiIndex)): - pytest.skip("missing value sorting order not defined for index type") +def test_sort_values_invalid_na_position(request, index_with_missing, na_position): + if isinstance(index_with_missing, MultiIndex): + request.node.add_marker( + pytest.mark.xfail( + reason="missing value sorting order not defined for index type" + ) + ) if na_position not in ["first", "last"]: with pytest.raises(ValueError, match=f"invalid na_position: {na_position}"): @@ -396,12 +400,16 @@ def test_sort_values_invalid_na_position(index_with_missing, na_position): @pytest.mark.parametrize("na_position", ["first", "last"]) -def test_sort_values_with_missing(index_with_missing, na_position): +def test_sort_values_with_missing(request, index_with_missing, na_position): # GH 35584. Test that sort_values works with missing values, # sort non-missing and place missing according to na_position - if isinstance(index_with_missing, (CategoricalIndex, MultiIndex)): - pytest.skip("missing value sorting order not defined for index type") + if isinstance(index_with_missing, MultiIndex): + request.node.add_marker( + pytest.mark.xfail(reason="missing value sorting order not implemented") + ) + elif isinstance(index_with_missing, CategoricalIndex): + pytest.skip("missing value sorting order not well-defined") missing_count = np.sum(index_with_missing.isna()) not_na_vals = index_with_missing[index_with_missing.notna()].values