Skip to content

Commit 6aaa76f

Browse files
authored
TST: Replace pytest.xfail (#38929)
1 parent 0efb5e8 commit 6aaa76f

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

pandas/tests/indexes/test_common.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -386,22 +386,30 @@ def test_asi8_deprecation(self, index):
386386

387387

388388
@pytest.mark.parametrize("na_position", [None, "middle"])
389-
def test_sort_values_invalid_na_position(index_with_missing, na_position):
390-
if isinstance(index_with_missing, (CategoricalIndex, MultiIndex)):
391-
pytest.xfail("missing value sorting order not defined for index type")
389+
def test_sort_values_invalid_na_position(request, index_with_missing, na_position):
390+
if isinstance(index_with_missing, MultiIndex):
391+
request.node.add_marker(
392+
pytest.mark.xfail(
393+
reason="missing value sorting order not defined for index type"
394+
)
395+
)
392396

393397
if na_position not in ["first", "last"]:
394398
with pytest.raises(ValueError, match=f"invalid na_position: {na_position}"):
395399
index_with_missing.sort_values(na_position=na_position)
396400

397401

398402
@pytest.mark.parametrize("na_position", ["first", "last"])
399-
def test_sort_values_with_missing(index_with_missing, na_position):
403+
def test_sort_values_with_missing(request, index_with_missing, na_position):
400404
# GH 35584. Test that sort_values works with missing values,
401405
# sort non-missing and place missing according to na_position
402406

403-
if isinstance(index_with_missing, (CategoricalIndex, MultiIndex)):
404-
pytest.xfail("missing value sorting order not defined for index type")
407+
if isinstance(index_with_missing, MultiIndex):
408+
request.node.add_marker(
409+
pytest.mark.xfail(reason="missing value sorting order not implemented")
410+
)
411+
elif isinstance(index_with_missing, CategoricalIndex):
412+
pytest.skip("missing value sorting order not well-defined")
405413

406414
missing_count = np.sum(index_with_missing.isna())
407415
not_na_vals = index_with_missing[index_with_missing.notna()].values

pandas/tests/indexes/test_setops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_union_different_types(request, index, index_fixture2):
4949
)
5050

5151
if any(isinstance(idx, pd.MultiIndex) for idx in (idx1, idx2)):
52-
pytest.xfail("This test doesn't consider multiindixes.")
52+
pytest.skip("This test doesn't consider multiindixes.")
5353

5454
if is_dtype_equal(idx1.dtype, idx2.dtype):
5555
pytest.skip("This test only considers non matching dtypes.")

pandas/tests/series/indexing/test_setitem.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,15 @@ def test_series_where(self, obj, key, expected):
328328
tm.assert_series_equal(res, expected)
329329

330330
def test_index_where(self, obj, key, expected, request):
331-
if obj.dtype == bool:
332-
msg = "Index/Series casting behavior inconsistent GH#38692"
333-
mark = pytest.xfail(reason=msg)
334-
request.node.add_marker(mark)
335-
336331
mask = np.zeros(obj.shape, dtype=bool)
337332
mask[key] = True
338333

334+
if obj.dtype == bool and not mask.all():
335+
# When mask is all True, casting behavior does not apply
336+
msg = "Index/Series casting behavior inconsistent GH#38692"
337+
mark = pytest.mark.xfail(reason=msg)
338+
request.node.add_marker(mark)
339+
339340
res = Index(obj).where(~mask, np.nan)
340341
tm.assert_index_equal(res, Index(expected))
341342

pandas/tests/series/indexing/test_where.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,6 @@ def test_where_datetimelike_categorical(tz_naive_fixture):
489489
tm.assert_series_equal(res, Series(dr))
490490

491491
# DataFrame.where
492-
if tz is None:
493-
res = pd.DataFrame(lvals).where(mask[:, None], pd.DataFrame(rvals))
494-
else:
495-
with pytest.xfail(reason="frame._values loses tz"):
496-
res = pd.DataFrame(lvals).where(mask[:, None], pd.DataFrame(rvals))
492+
res = pd.DataFrame(lvals).where(mask[:, None], pd.DataFrame(rvals))
497493

498494
tm.assert_frame_equal(res, pd.DataFrame(dr))

pandas/tests/series/test_arithmetic.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,18 @@ def test_align_date_objects_with_datetimeindex(self):
737737
class TestNamePreservation:
738738
@pytest.mark.parametrize("box", [list, tuple, np.array, Index, Series, pd.array])
739739
@pytest.mark.parametrize("flex", [True, False])
740-
def test_series_ops_name_retention(self, flex, box, names, all_binary_operators):
740+
def test_series_ops_name_retention(
741+
self, request, flex, box, names, all_binary_operators
742+
):
741743
# GH#33930 consistent name renteiton
742744
op = all_binary_operators
743745

744-
if op is ops.rfloordiv and box in [list, tuple]:
745-
pytest.xfail("op fails because of inconsistent ndarray-wrapping GH#28759")
746+
if op is ops.rfloordiv and box in [list, tuple] and not flex:
747+
request.node.add_marker(
748+
pytest.mark.xfail(
749+
reason="op fails because of inconsistent ndarray-wrapping GH#28759"
750+
)
751+
)
746752

747753
left = Series(range(10), name=names[0])
748754
right = Series(range(10), name=names[1])

0 commit comments

Comments
 (0)