diff --git a/pandas/tests/indexes/test_common.py b/pandas/tests/indexes/test_common.py index bc1295cc0a0ce..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.xfail("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.xfail("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 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])