Skip to content

Commit 22dbef1

Browse files
authored
TST: tighten xfails (#38309)
* TST: tighten xfails * troubleshoot
1 parent 122ae44 commit 22dbef1

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

pandas/tests/arrays/test_datetimelike.py

+10-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import numpy as np
55
import pytest
6-
import pytz
76

87
from pandas._libs import NaT, OutOfBoundsDatetime, Timestamp
98
from pandas.compat.numpy import np_version_under1p18
@@ -269,18 +268,16 @@ def test_searchsorted(self):
269268
assert result == 10
270269

271270
@pytest.mark.parametrize("box", [None, "index", "series"])
272-
def test_searchsorted_castable_strings(self, arr1d, box):
271+
def test_searchsorted_castable_strings(self, arr1d, box, request):
273272
if isinstance(arr1d, DatetimeArray):
274273
tz = arr1d.tz
275-
if (
276-
tz is not None
277-
and tz is not pytz.UTC
278-
and not isinstance(tz, pytz._FixedOffset)
279-
):
274+
ts1, ts2 = arr1d[1:3]
275+
if tz is not None and ts1.tz.tzname(ts1) != ts2.tz.tzname(ts2):
280276
# If we have e.g. tzutc(), when we cast to string and parse
281277
# back we get pytz.UTC, and then consider them different timezones
282278
# so incorrectly raise.
283-
pytest.xfail(reason="timezone comparisons inconsistent")
279+
mark = pytest.mark.xfail(reason="timezone comparisons inconsistent")
280+
request.node.add_marker(mark)
284281

285282
arr = arr1d
286283
if box is None:
@@ -391,19 +388,17 @@ def test_setitem(self):
391388
expected[:2] = expected[-2:]
392389
tm.assert_numpy_array_equal(arr.asi8, expected)
393390

394-
def test_setitem_strs(self, arr1d):
391+
def test_setitem_strs(self, arr1d, request):
395392
# Check that we parse strs in both scalar and listlike
396393
if isinstance(arr1d, DatetimeArray):
397394
tz = arr1d.tz
398-
if (
399-
tz is not None
400-
and tz is not pytz.UTC
401-
and not isinstance(tz, pytz._FixedOffset)
402-
):
395+
ts1, ts2 = arr1d[-2:]
396+
if tz is not None and ts1.tz.tzname(ts1) != ts2.tz.tzname(ts2):
403397
# If we have e.g. tzutc(), when we cast to string and parse
404398
# back we get pytz.UTC, and then consider them different timezones
405399
# so incorrectly raise.
406-
pytest.xfail(reason="timezone comparisons inconsistent")
400+
mark = pytest.mark.xfail(reason="timezone comparisons inconsistent")
401+
request.node.add_marker(mark)
407402

408403
# Setting list-like of strs
409404
expected = arr1d.copy()

pandas/tests/base/test_conversion.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,16 @@ def test_array_multiindex_raises():
328328
),
329329
],
330330
)
331-
def test_to_numpy(array, expected, index_or_series_or_array):
331+
def test_to_numpy(array, expected, index_or_series_or_array, request):
332332
box = index_or_series_or_array
333333
thing = box(array)
334334

335335
if array.dtype.name in ("Int64", "Sparse[int64, 0]") and box is pd.Index:
336336
pytest.skip(f"No index type for {array.dtype}")
337337

338338
if array.dtype.name == "int64" and box is pd.array:
339-
pytest.xfail("thing is Int64 and to_numpy() returns object")
339+
mark = pytest.mark.xfail(reason="thing is Int64 and to_numpy() returns object")
340+
request.node.add_marker(mark)
340341

341342
result = thing.to_numpy()
342343
tm.assert_numpy_array_equal(result, expected)

pandas/tests/indexes/test_numpy_compat.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,16 @@ def test_numpy_ufuncs_basic(index, func):
7474
@pytest.mark.parametrize(
7575
"func", [np.isfinite, np.isinf, np.isnan, np.signbit], ids=lambda x: x.__name__
7676
)
77-
def test_numpy_ufuncs_other(index, func):
77+
def test_numpy_ufuncs_other(index, func, request):
7878
# test ufuncs of numpy, see:
7979
# https://numpy.org/doc/stable/reference/ufuncs.html
8080

8181
if isinstance(index, (DatetimeIndex, TimedeltaIndex)):
8282
if isinstance(index, DatetimeIndex) and index.tz is not None:
8383
if func in [np.isfinite, np.isnan, np.isinf]:
84-
pytest.xfail(reason="__array_ufunc__ is not defined")
84+
if not np_version_under1p17:
85+
mark = pytest.mark.xfail(reason="__array_ufunc__ is not defined")
86+
request.node.add_marker(mark)
8587

8688
if not np_version_under1p18 and func in [np.isfinite, np.isinf, np.isnan]:
8789
# numpy 1.18(dev) changed isinf and isnan to not raise on dt64/tfd64

pandas/tests/series/test_arithmetic.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -756,12 +756,15 @@ def test_align_date_objects_with_datetimeindex(self):
756756
)
757757
@pytest.mark.parametrize("box", [list, tuple, np.array, pd.Index, pd.Series, pd.array])
758758
@pytest.mark.parametrize("flex", [True, False])
759-
def test_series_ops_name_retention(flex, box, names, all_binary_operators):
759+
def test_series_ops_name_retention(flex, box, names, all_binary_operators, request):
760760
# GH#33930 consistent name retention
761761
op = all_binary_operators
762762

763-
if op is ops.rfloordiv and box in [list, tuple]:
764-
pytest.xfail("op fails because of inconsistent ndarray-wrapping GH#28759")
763+
if op is ops.rfloordiv and box in [list, tuple] and not flex:
764+
mark = pytest.mark.xfail(
765+
reason="op fails because of inconsistent ndarray-wrapping GH#28759"
766+
)
767+
request.node.add_marker(mark)
765768

766769
left = Series(range(10), name=names[0])
767770
right = Series(range(10), name=names[1])

0 commit comments

Comments
 (0)