From 344567a013d36523e89156d1f659773fa4ab963c Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 27 Nov 2021 18:27:55 -0800 Subject: [PATCH] TST: skip->xfail --- pandas/tests/arrays/masked/test_arithmetic.py | 8 ++-- pandas/tests/base/test_conversion.py | 9 ++--- pandas/tests/base/test_misc.py | 11 +++--- pandas/tests/extension/test_datetime.py | 7 +--- pandas/tests/indexes/test_base.py | 11 +++--- pandas/tests/indexing/test_coercion.py | 12 ++++-- pandas/tests/io/parser/test_skiprows.py | 5 ++- pandas/tests/io/pytables/test_round_trip.py | 6 ++- pandas/tests/reductions/test_reductions.py | 7 ++-- pandas/tests/series/indexing/test_setitem.py | 2 + pandas/tests/series/methods/test_diff.py | 37 ++++++++++--------- pandas/tests/series/test_ufunc.py | 7 +++- pandas/tests/strings/test_strings.py | 7 +++- 13 files changed, 72 insertions(+), 57 deletions(-) diff --git a/pandas/tests/arrays/masked/test_arithmetic.py b/pandas/tests/arrays/masked/test_arithmetic.py index 57086bf92b890..fae956693093b 100644 --- a/pandas/tests/arrays/masked/test_arithmetic.py +++ b/pandas/tests/arrays/masked/test_arithmetic.py @@ -48,9 +48,11 @@ def test_array_scalar_like_equivalence(data, all_arithmetic_operators): tm.assert_extension_array_equal(result, expected) -def test_array_NA(data, all_arithmetic_operators): - if "truediv" in all_arithmetic_operators: - pytest.skip("division with pd.NA raises") +def test_array_NA(data, all_arithmetic_operators, request): + if "truediv" in all_arithmetic_operators and data[0].dtype.kind != "f": + mark = pytest.mark.xfail(reason="division with pd.NA fails") + request.node.add_marker(mark) + data, _ = data op = tm.get_op_from_name(all_arithmetic_operators) check_skip(data, all_arithmetic_operators) diff --git a/pandas/tests/base/test_conversion.py b/pandas/tests/base/test_conversion.py index 7045a0abbeb81..c483d4354a7b9 100644 --- a/pandas/tests/base/test_conversion.py +++ b/pandas/tests/base/test_conversion.py @@ -265,10 +265,12 @@ def test_numpy_array_all_dtypes(any_numpy_dtype): ), ], ) -def test_array(arr, attr, index_or_series): +def test_array(arr, attr, index_or_series, request): box = index_or_series if arr.dtype.name in ("Int64", "Sparse[int64, 0]") and box is pd.Index: - pytest.skip(f"No index type for {arr.dtype}") + mark = pytest.mark.xfail(reason="Needs EA-Backed Index") + request.node.add_marker(mark) + result = box(arr, copy=False).array if attr: @@ -341,9 +343,6 @@ def test_to_numpy(arr, expected, index_or_series_or_array, request): box = index_or_series_or_array thing = box(arr) - if arr.dtype.name in ("Int64", "Sparse[int64, 0]") and box is pd.Index: - pytest.skip(f"No index type for {arr.dtype}") - if arr.dtype.name == "int64" and box is pd.array: mark = pytest.mark.xfail(reason="thing is Int64 and to_numpy() returns object") request.node.add_marker(mark) diff --git a/pandas/tests/base/test_misc.py b/pandas/tests/base/test_misc.py index c0250e2b3e958..aaaec46399fa8 100644 --- a/pandas/tests/base/test_misc.py +++ b/pandas/tests/base/test_misc.py @@ -15,7 +15,6 @@ import pandas as pd from pandas import ( - DataFrame, Index, Series, ) @@ -33,10 +32,11 @@ ("floordiv", "//"), ], ) -@pytest.mark.parametrize("klass", [Series, DataFrame]) -def test_binary_ops_docstring(klass, op_name, op): +def test_binary_ops_docstring(frame_or_series, op_name, op): # not using the all_arithmetic_functions fixture with _get_opstr # as _get_opstr is used internally in the dynamic implementation of the docstring + klass = frame_or_series + operand1 = klass.__name__.lower() operand2 = "other" expected_str = " ".join([operand1, op, operand2]) @@ -134,12 +134,11 @@ def test_searchsorted(index_or_series_obj): assert 0 <= index <= len(obj) -def test_access_by_position(index): +def test_access_by_position(index_flat): + index = index_flat if len(index) == 0: pytest.skip("Test doesn't make sense on empty data") - elif isinstance(index, pd.MultiIndex): - pytest.skip("Can't instantiate Series from MultiIndex") series = Series(index) assert index[0] == series.iloc[0] diff --git a/pandas/tests/extension/test_datetime.py b/pandas/tests/extension/test_datetime.py index f13b24fabaf34..e2c4a3fd49969 100644 --- a/pandas/tests/extension/test_datetime.py +++ b/pandas/tests/extension/test_datetime.py @@ -114,12 +114,7 @@ def test_combine_add(self, data_repeated): class TestInterface(BaseDatetimeTests, base.BaseInterfaceTests): - def test_array_interface(self, data): - if data.tz: - # np.asarray(DTA) is currently always tz-naive. - pytest.skip("GH-23569") - else: - super().test_array_interface(data) + pass class TestArithmeticOps(BaseDatetimeTests, base.BaseArithmeticOpsTests): diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 5df1f83028133..bf69f6f48f26d 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -822,14 +822,13 @@ def test_isin_nan_common_float64(self, request, nulls_fixture): pytest.mark.xfail(reason="Float64Index cannot contain pd.NA") ) - tm.assert_numpy_array_equal( - Float64Index([1.0, nulls_fixture]).isin([np.nan]), np.array([False, True]) - ) + idx = Float64Index([1.0, nulls_fixture]) + res = idx.isin([np.nan]) + tm.assert_numpy_array_equal(res, np.array([False, True])) # we cannot compare NaT with NaN - tm.assert_numpy_array_equal( - Float64Index([1.0, nulls_fixture]).isin([pd.NaT]), np.array([False, False]) - ) + res = idx.isin([pd.NaT]) + tm.assert_numpy_array_equal(res, np.array([False, False])) @pytest.mark.parametrize("level", [0, -1]) @pytest.mark.parametrize( diff --git a/pandas/tests/indexing/test_coercion.py b/pandas/tests/indexing/test_coercion.py index 0174219892d92..075007c6b9870 100644 --- a/pandas/tests/indexing/test_coercion.py +++ b/pandas/tests/indexing/test_coercion.py @@ -610,10 +610,12 @@ def test_where_object(self, index_or_series, fill_val, exp_dtype): "fill_val,exp_dtype", [(1, np.int64), (1.1, np.float64), (1 + 1j, np.complex128), (True, object)], ) - def test_where_int64(self, index_or_series, fill_val, exp_dtype): + def test_where_int64(self, index_or_series, fill_val, exp_dtype, request): klass = index_or_series if klass is pd.Index and exp_dtype is np.complex128: - pytest.skip("Complex Index not supported") + mark = pytest.mark.xfail(reason="Complex Index not supported") + request.node.add_marker(mark) + obj = klass([1, 2, 3, 4]) assert obj.dtype == np.int64 cond = klass([True, False, True, False]) @@ -632,10 +634,12 @@ def test_where_int64(self, index_or_series, fill_val, exp_dtype): "fill_val, exp_dtype", [(1, np.float64), (1.1, np.float64), (1 + 1j, np.complex128), (True, object)], ) - def test_where_float64(self, index_or_series, fill_val, exp_dtype): + def test_where_float64(self, index_or_series, fill_val, exp_dtype, request): klass = index_or_series if klass is pd.Index and exp_dtype is np.complex128: - pytest.skip("Complex Index not supported") + mark = pytest.mark.xfail(reason="Complex Index not supported") + request.node.add_marker(mark) + obj = klass([1.1, 2.2, 3.3, 4.4]) assert obj.dtype == np.float64 cond = klass([True, False, True, False]) diff --git a/pandas/tests/io/parser/test_skiprows.py b/pandas/tests/io/parser/test_skiprows.py index 627bda44016e9..5b722b54da693 100644 --- a/pandas/tests/io/parser/test_skiprows.py +++ b/pandas/tests/io/parser/test_skiprows.py @@ -182,7 +182,7 @@ def test_skip_row_with_newline_and_quote(all_parsers, data, exp_data): @pytest.mark.parametrize( "line_terminator", ["\n", "\r\n", "\r"] # "LF" # "CRLF" # "CR" ) -def test_skiprows_lineterminator(all_parsers, line_terminator): +def test_skiprows_lineterminator(all_parsers, line_terminator, request): # see gh-9079 parser = all_parsers data = "\n".join( @@ -203,7 +203,8 @@ def test_skiprows_lineterminator(all_parsers, line_terminator): ) if parser.engine == "python" and line_terminator == "\r": - pytest.skip("'CR' not respect with the Python parser yet") + mark = pytest.mark.xfail(reason="'CR' not respect with the Python parser yet") + request.node.add_marker(mark) data = data.replace("\n", line_terminator) result = parser.read_csv( diff --git a/pandas/tests/io/pytables/test_round_trip.py b/pandas/tests/io/pytables/test_round_trip.py index eba21bd94444a..9d7375b0f97e2 100644 --- a/pandas/tests/io/pytables/test_round_trip.py +++ b/pandas/tests/io/pytables/test_round_trip.py @@ -9,6 +9,7 @@ import pytest from pandas._libs.tslibs import Timestamp +from pandas.compat import is_platform_windows import pandas as pd from pandas import ( @@ -350,7 +351,10 @@ def test_timeseries_preepoch(setup_path): try: _check_roundtrip(ts, tm.assert_series_equal, path=setup_path) except OverflowError: - pytest.skip("known failure on some windows platforms") + if is_platform_windows(): + pytest.xfail("known failure on some windows platforms") + else: + raise @pytest.mark.parametrize( diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 3a8ae03015628..cc7121d2f4656 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -79,17 +79,18 @@ def test_ops(self, opname, obj): ("boolean", True), ], ) - def test_nanminmax(self, opname, dtype, val, index_or_series): + def test_nanminmax(self, opname, dtype, val, index_or_series, request): # GH#7261 klass = index_or_series if dtype in ["Int64", "boolean"] and klass == Index: - pytest.skip("EAs can't yet be stored in an index") + mark = pytest.mark.xfail(reason="Need EA-backed Index") + request.node.add_marker(mark) def check_missing(res): if dtype == "datetime64[ns]": return res is NaT - elif dtype == "Int64": + elif dtype in ["Int64", "boolean"]: return res is pd.NA else: return isna(res) diff --git a/pandas/tests/series/indexing/test_setitem.py b/pandas/tests/series/indexing/test_setitem.py index ea754127b98e9..5f96078ba70b1 100644 --- a/pandas/tests/series/indexing/test_setitem.py +++ b/pandas/tests/series/indexing/test_setitem.py @@ -652,6 +652,7 @@ def test_series_where(self, obj, key, expected, val, is_inplace): def test_index_where(self, obj, key, expected, val, request): if Index(obj).dtype != obj.dtype: + # TODO(ExtensionIndex): Should become unreachable pytest.skip("test not applicable for this dtype") mask = np.zeros(obj.shape, dtype=bool) @@ -667,6 +668,7 @@ def test_index_where(self, obj, key, expected, val, request): def test_index_putmask(self, obj, key, expected, val): if Index(obj).dtype != obj.dtype: + # TODO(ExtensionIndex): Should become unreachable pytest.skip("test not applicable for this dtype") mask = np.zeros(obj.shape, dtype=bool) diff --git a/pandas/tests/series/methods/test_diff.py b/pandas/tests/series/methods/test_diff.py index 1fbce249af6d2..938a0f9ac49d1 100644 --- a/pandas/tests/series/methods/test_diff.py +++ b/pandas/tests/series/methods/test_diff.py @@ -11,21 +11,22 @@ class TestSeriesDiff: def test_diff_np(self): - pytest.skip("skipping due to Series no longer being an ndarray") + # TODO(__array_function__): could make np.diff return a Series + # matching ser.diff() - # no longer works as the return type of np.diff is now nd.array - s = Series(np.arange(5)) + ser = Series(np.arange(5)) - r = np.diff(s) - tm.assert_series_equal(Series([np.nan, 0, 0, 0, np.nan]), r) + res = np.diff(ser) + expected = np.array([1, 1, 1, 1]) + tm.assert_numpy_array_equal(res, expected) def test_diff_int(self): # int dtype a = 10000000000000000 b = a + 1 - s = Series([a, b]) + ser = Series([a, b]) - result = s.diff() + result = ser.diff() assert result[1] == 1 def test_diff_tz(self): @@ -43,10 +44,11 @@ def test_diff_tz(self): expected = ts - ts tm.assert_series_equal(result, expected) + def test_diff_dt64(self): # datetime diff (GH#3100) - s = Series(date_range("20130102", periods=5)) - result = s.diff() - expected = s - s.shift(1) + ser = Series(date_range("20130102", periods=5)) + result = ser.diff() + expected = ser - ser.shift(1) tm.assert_series_equal(result, expected) # timedelta diff @@ -54,11 +56,12 @@ def test_diff_tz(self): expected = expected.diff() # previously expected tm.assert_series_equal(result, expected) + def test_diff_dt64tz(self): # with tz - s = Series( + ser = Series( date_range("2000-01-01 09:00:00", periods=5, tz="US/Eastern"), name="foo" ) - result = s.diff() + result = ser.diff() expected = Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4), name="foo") tm.assert_series_equal(result, expected) @@ -68,14 +71,14 @@ def test_diff_tz(self): ) def test_diff_bool(self, input, output, diff): # boolean series (test for fixing #17294) - s = Series(input) - result = s.diff() + ser = Series(input) + result = ser.diff() expected = Series(output) tm.assert_series_equal(result, expected) def test_diff_object_dtype(self): # object series - s = Series([False, True, 5.0, np.nan, True, False]) - result = s.diff() - expected = s - s.shift(1) + ser = Series([False, True, 5.0, np.nan, True, False]) + result = ser.diff() + expected = ser - ser.shift(1) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/series/test_ufunc.py b/pandas/tests/series/test_ufunc.py index 15b2ff36cff1e..70638ee8e249b 100644 --- a/pandas/tests/series/test_ufunc.py +++ b/pandas/tests/series/test_ufunc.py @@ -171,12 +171,15 @@ def test_binary_ufunc_scalar(ufunc, sparse, flip, arrays_for_binary_ufunc): @pytest.mark.parametrize("sparse", SPARSE, ids=SPARSE_IDS) @pytest.mark.parametrize("shuffle", SHUFFLE) @pytest.mark.filterwarnings("ignore:divide by zero:RuntimeWarning") -def test_multiple_output_binary_ufuncs(ufunc, sparse, shuffle, arrays_for_binary_ufunc): +def test_multiple_output_binary_ufuncs( + ufunc, sparse, shuffle, arrays_for_binary_ufunc, request +): # Test that # the same conditions from binary_ufunc_scalar apply to # ufuncs with multiple outputs. if sparse and ufunc is np.divmod: - pytest.skip("sparse divmod not implemented.") + mark = pytest.mark.xfail(reason="sparse divmod not implemented") + request.node.add_marker(mark) a1, a2 = arrays_for_binary_ufunc # work around https://github.com/pandas-dev/pandas/issues/26987 diff --git a/pandas/tests/strings/test_strings.py b/pandas/tests/strings/test_strings.py index ba942d740ac8b..3e49d6367ffd9 100644 --- a/pandas/tests/strings/test_strings.py +++ b/pandas/tests/strings/test_strings.py @@ -364,9 +364,12 @@ def test_len_mixed(): ("rindex", "E", 0, 5, [4, 3, 1, 4]), ], ) -def test_index(method, sub, start, end, index_or_series, any_string_dtype, expected): +def test_index( + method, sub, start, end, index_or_series, any_string_dtype, expected, request +): if index_or_series is Index and not any_string_dtype == "object": - pytest.skip("Index cannot yet be backed by a StringArray/ArrowStringArray") + mark = pytest.mark.xfail(reason="Need EA-backed Index") + request.node.add_marker(mark) obj = index_or_series( ["ABCDEFG", "BCDEFEF", "DEFGHIJEF", "EFGHEF"], dtype=any_string_dtype