diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index 159f52a4c7c25..c489aa5867632 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -3,7 +3,6 @@ import numpy as np import pytest -import pytz from pandas._libs import NaT, OutOfBoundsDatetime, Timestamp from pandas.compat.numpy import np_version_under1p18 @@ -269,18 +268,16 @@ def test_searchsorted(self): assert result == 10 @pytest.mark.parametrize("box", [None, "index", "series"]) - def test_searchsorted_castable_strings(self, arr1d, box): + def test_searchsorted_castable_strings(self, arr1d, box, request): if isinstance(arr1d, DatetimeArray): tz = arr1d.tz - if ( - tz is not None - and tz is not pytz.UTC - and not isinstance(tz, pytz._FixedOffset) - ): + ts1, ts2 = arr1d[1:3] + if tz is not None and ts1.tz.tzname(ts1) != ts2.tz.tzname(ts2): # If we have e.g. tzutc(), when we cast to string and parse # back we get pytz.UTC, and then consider them different timezones # so incorrectly raise. - pytest.xfail(reason="timezone comparisons inconsistent") + mark = pytest.mark.xfail(reason="timezone comparisons inconsistent") + request.node.add_marker(mark) arr = arr1d if box is None: @@ -391,19 +388,17 @@ def test_setitem(self): expected[:2] = expected[-2:] tm.assert_numpy_array_equal(arr.asi8, expected) - def test_setitem_strs(self, arr1d): + def test_setitem_strs(self, arr1d, request): # Check that we parse strs in both scalar and listlike if isinstance(arr1d, DatetimeArray): tz = arr1d.tz - if ( - tz is not None - and tz is not pytz.UTC - and not isinstance(tz, pytz._FixedOffset) - ): + ts1, ts2 = arr1d[-2:] + if tz is not None and ts1.tz.tzname(ts1) != ts2.tz.tzname(ts2): # If we have e.g. tzutc(), when we cast to string and parse # back we get pytz.UTC, and then consider them different timezones # so incorrectly raise. - pytest.xfail(reason="timezone comparisons inconsistent") + mark = pytest.mark.xfail(reason="timezone comparisons inconsistent") + request.node.add_marker(mark) # Setting list-like of strs expected = arr1d.copy() diff --git a/pandas/tests/base/test_conversion.py b/pandas/tests/base/test_conversion.py index 668954a3f4a0b..cc4aed5e4413d 100644 --- a/pandas/tests/base/test_conversion.py +++ b/pandas/tests/base/test_conversion.py @@ -328,7 +328,7 @@ def test_array_multiindex_raises(): ), ], ) -def test_to_numpy(array, expected, index_or_series_or_array): +def test_to_numpy(array, expected, index_or_series_or_array, request): box = index_or_series_or_array thing = box(array) @@ -336,7 +336,8 @@ def test_to_numpy(array, expected, index_or_series_or_array): pytest.skip(f"No index type for {array.dtype}") if array.dtype.name == "int64" and box is pd.array: - pytest.xfail("thing is Int64 and to_numpy() returns object") + mark = pytest.mark.xfail(reason="thing is Int64 and to_numpy() returns object") + request.node.add_marker(mark) result = thing.to_numpy() tm.assert_numpy_array_equal(result, expected) diff --git a/pandas/tests/indexes/test_numpy_compat.py b/pandas/tests/indexes/test_numpy_compat.py index b71417b2a625d..8bfb97ca494e6 100644 --- a/pandas/tests/indexes/test_numpy_compat.py +++ b/pandas/tests/indexes/test_numpy_compat.py @@ -74,14 +74,16 @@ def test_numpy_ufuncs_basic(index, func): @pytest.mark.parametrize( "func", [np.isfinite, np.isinf, np.isnan, np.signbit], ids=lambda x: x.__name__ ) -def test_numpy_ufuncs_other(index, func): +def test_numpy_ufuncs_other(index, func, request): # test ufuncs of numpy, see: # https://numpy.org/doc/stable/reference/ufuncs.html if isinstance(index, (DatetimeIndex, TimedeltaIndex)): if isinstance(index, DatetimeIndex) and index.tz is not None: if func in [np.isfinite, np.isnan, np.isinf]: - pytest.xfail(reason="__array_ufunc__ is not defined") + if not np_version_under1p17: + mark = pytest.mark.xfail(reason="__array_ufunc__ is not defined") + request.node.add_marker(mark) if not np_version_under1p18 and func in [np.isfinite, np.isinf, np.isnan]: # numpy 1.18(dev) changed isinf and isnan to not raise on dt64/tfd64 diff --git a/pandas/tests/series/test_arithmetic.py b/pandas/tests/series/test_arithmetic.py index 09109447e799a..b204d92b9122f 100644 --- a/pandas/tests/series/test_arithmetic.py +++ b/pandas/tests/series/test_arithmetic.py @@ -756,12 +756,15 @@ def test_align_date_objects_with_datetimeindex(self): ) @pytest.mark.parametrize("box", [list, tuple, np.array, pd.Index, pd.Series, pd.array]) @pytest.mark.parametrize("flex", [True, False]) -def test_series_ops_name_retention(flex, box, names, all_binary_operators): +def test_series_ops_name_retention(flex, box, names, all_binary_operators, request): # GH#33930 consistent name retention 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: + mark = pytest.mark.xfail( + reason="op fails because of inconsistent ndarray-wrapping GH#28759" + ) + request.node.add_marker(mark) left = Series(range(10), name=names[0]) right = Series(range(10), name=names[1])