diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index a89946d1f8cc8..6248154422252 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -1077,14 +1077,16 @@ def shares_memory(left, right) -> bool: if isinstance(left, NDArrayBackedExtensionArray): return shares_memory(left._ndarray, right) - if isinstance(left, pd.SparseArray): + if isinstance(left, pd.core.arrays.SparseArray): return shares_memory(left.sp_values, right) if isinstance(left, ExtensionArray) and left.dtype == "string[pyarrow]": # https://github.com/pandas-dev/pandas/pull/43930#discussion_r736862669 if isinstance(right, ExtensionArray) and right.dtype == "string[pyarrow]": - left_pa_data = left._data - right_pa_data = right._data + # error: "ExtensionArray" has no attribute "_data" + left_pa_data = left._data # type: ignore[attr-defined] + # error: "ExtensionArray" has no attribute "_data" + right_pa_data = right._data # type: ignore[attr-defined] left_buf1 = left_pa_data.chunk(0).buffers()[1] right_buf1 = right_pa_data.chunk(0).buffers()[1] return left_buf1 == right_buf1 diff --git a/pandas/tests/apply/test_frame_transform.py b/pandas/tests/apply/test_frame_transform.py index ade8df6fbfc0e..7434a7df37629 100644 --- a/pandas/tests/apply/test_frame_transform.py +++ b/pandas/tests/apply/test_frame_transform.py @@ -160,8 +160,6 @@ def test_transform_bad_dtype(op, frame_or_series, request): @pytest.mark.parametrize("op", frame_kernels_raise) def test_transform_partial_failure_typeerror(op): # GH 35964 - if op == "rank": - pytest.skip("GH 40418: rank does not raise a TypeError") # Using object makes most transform kernels fail df = DataFrame({"A": 3 * [object], "B": [1, 2, 3]}) diff --git a/pandas/tests/extension/arrow/test_bool.py b/pandas/tests/extension/arrow/test_bool.py index 320bfc13f7032..9564239f119f3 100644 --- a/pandas/tests/extension/arrow/test_bool.py +++ b/pandas/tests/extension/arrow/test_bool.py @@ -41,8 +41,7 @@ class BaseArrowTests: class TestDtype(BaseArrowTests, base.BaseDtypeTests): - def test_array_type_with_arg(self, data, dtype): - pytest.skip("GH-22666") + pass class TestInterface(BaseArrowTests, base.BaseInterfaceTests): @@ -63,9 +62,6 @@ def test_contains(self, data, data_missing): class TestConstructors(BaseArrowTests, base.BaseConstructorsTests): - def test_from_dtype(self, data): - pytest.skip("GH-22666") - # seems like some bug in isna on empty BoolArray returning floats. @pytest.mark.xfail(reason="bad is-na for empty data") def test_from_sequence_from_cls(self, data): diff --git a/pandas/tests/extension/test_boolean.py b/pandas/tests/extension/test_boolean.py index b86122c8d1ee1..0212610ec270f 100644 --- a/pandas/tests/extension/test_boolean.py +++ b/pandas/tests/extension/test_boolean.py @@ -208,13 +208,13 @@ def test_searchsorted(self, data_for_sorting, as_series): sorter = np.array([1, 0]) assert data_for_sorting.searchsorted(a, sorter=sorter) == 0 - @pytest.mark.skip(reason="uses nullable integer") + @pytest.mark.xfail(reason="uses nullable integer") def test_value_counts(self, all_data, dropna): return super().test_value_counts(all_data, dropna) - @pytest.mark.skip(reason="uses nullable integer") + @pytest.mark.xfail(reason="uses nullable integer") def test_value_counts_with_normalize(self, data): - pass + super().test_value_counts_with_normalize(data) def test_argmin_argmax(self, data_for_sorting, data_missing_for_sorting): # override because there are only 2 unique values diff --git a/pandas/tests/extension/test_floating.py b/pandas/tests/extension/test_floating.py index b72ad2739949e..440190bd6c2f9 100644 --- a/pandas/tests/extension/test_floating.py +++ b/pandas/tests/extension/test_floating.py @@ -169,7 +169,9 @@ class TestMissing(base.BaseMissingTests): class TestMethods(base.BaseMethodsTests): + # TODO(ExtensionIndex): re-enable @pytest.mark.skip(reason="uses nullable integer") + @pytest.mark.parametrize("dropna", [True, False]) def test_value_counts(self, all_data, dropna): all_data = all_data[:10] if dropna: @@ -183,9 +185,9 @@ def test_value_counts(self, all_data, dropna): self.assert_series_equal(result, expected) - @pytest.mark.skip(reason="uses nullable integer") + @pytest.mark.xfail(reason="uses nullable integer") def test_value_counts_with_normalize(self, data): - pass + super().test_value_counts_with_normalize(data) class TestCasting(base.BaseCastingTests): diff --git a/pandas/tests/extension/test_integer.py b/pandas/tests/extension/test_integer.py index 6266462adc599..8c5aadd7a9bcb 100644 --- a/pandas/tests/extension/test_integer.py +++ b/pandas/tests/extension/test_integer.py @@ -192,6 +192,7 @@ class TestMissing(base.BaseMissingTests): class TestMethods(base.BaseMethodsTests): + # TODO(ExtensionIndex): re-enable @pytest.mark.skip(reason="uses nullable integer") @pytest.mark.parametrize("dropna", [True, False]) def test_value_counts(self, all_data, dropna): @@ -207,9 +208,9 @@ def test_value_counts(self, all_data, dropna): self.assert_series_equal(result, expected) - @pytest.mark.skip(reason="uses nullable integer") + @pytest.mark.xfail(reason="uses nullable integer") def test_value_counts_with_normalize(self, data): - pass + super().test_value_counts_with_normalize(data) class TestCasting(base.BaseCastingTests): diff --git a/pandas/tests/extension/test_interval.py b/pandas/tests/extension/test_interval.py index 24c0d619e2b1a..fada6ea9281aa 100644 --- a/pandas/tests/extension/test_interval.py +++ b/pandas/tests/extension/test_interval.py @@ -95,10 +95,7 @@ class TestGrouping(BaseInterval, base.BaseGroupbyTests): class TestInterface(BaseInterval, base.BaseInterfaceTests): - def test_view(self, data): - # __setitem__ incorrectly makes a copy (GH#27147), so we only - # have a smoke-test - data.view() + pass class TestReduce(base.BaseNoReduceTests): diff --git a/pandas/tests/extension/test_sparse.py b/pandas/tests/extension/test_sparse.py index 940f2257b5eba..cadc688265c89 100644 --- a/pandas/tests/extension/test_sparse.py +++ b/pandas/tests/extension/test_sparse.py @@ -116,9 +116,6 @@ def test_array_type_with_arg(self, data, dtype): class TestInterface(BaseSparseTests, base.BaseInterfaceTests): - def test_no_values_attribute(self, data): - pytest.skip("We have values") - def test_copy(self, data): # __setitem__ does not work, so we only have a smoke-test data.copy() diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index 3632737e436f4..6429544869ac2 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -1492,7 +1492,7 @@ def test_reductions_deprecation_level_argument( def test_reductions_skipna_none_raises(self, frame_or_series, reduction_functions): if reduction_functions in ["count", "mad"]: - pytest.skip("Count does not accept skipna. Mad needs a depreaction cycle.") + pytest.skip("Count does not accept skipna. Mad needs a deprecation cycle.") obj = frame_or_series([1, 2, 3]) msg = 'For argument "skipna" expected type bool, received type NoneType.' with pytest.raises(ValueError, match=msg): diff --git a/pandas/tests/generic/test_to_xarray.py b/pandas/tests/generic/test_to_xarray.py index 556ae8baafd11..1fbd82f01213b 100644 --- a/pandas/tests/generic/test_to_xarray.py +++ b/pandas/tests/generic/test_to_xarray.py @@ -30,9 +30,9 @@ def df(self): } ) - def test_to_xarray_index_types(self, index, df): - if isinstance(index, MultiIndex): - pytest.skip("MultiIndex is tested separately") + def test_to_xarray_index_types(self, index_flat, df): + index = index_flat + # MultiIndex is tested in test_to_xarray_with_multiindex if len(index) == 0: pytest.skip("Test doesn't make sense for empty index") @@ -86,9 +86,9 @@ def test_to_xarray_with_multiindex(self, df): @td.skip_if_no("xarray") class TestSeriesToXArray: - def test_to_xarray_index_types(self, index): - if isinstance(index, MultiIndex): - pytest.skip("MultiIndex is tested separately") + def test_to_xarray_index_types(self, index_flat): + index = index_flat + # MultiIndex is tested in test_to_xarray_with_multiindex from xarray import DataArray diff --git a/pandas/tests/indexes/interval/test_constructors.py b/pandas/tests/indexes/interval/test_constructors.py index 91a669b86e23a..2ada97c0965f6 100644 --- a/pandas/tests/indexes/interval/test_constructors.py +++ b/pandas/tests/indexes/interval/test_constructors.py @@ -178,9 +178,6 @@ def test_constructor_string(self, constructor, breaks): @pytest.mark.parametrize("cat_constructor", [Categorical, CategoricalIndex]) def test_constructor_categorical_valid(self, constructor, cat_constructor): # GH 21243/21253 - if isinstance(constructor, partial) and constructor.func is Index: - # Index is defined to create CategoricalIndex from categorical data - pytest.skip() breaks = np.arange(10, dtype="int64") expected = IntervalIndex.from_breaks(breaks) diff --git a/pandas/tests/indexes/multi/test_analytics.py b/pandas/tests/indexes/multi/test_analytics.py index 9140983ecc583..629cd7eac29b0 100644 --- a/pandas/tests/indexes/multi/test_analytics.py +++ b/pandas/tests/indexes/multi/test_analytics.py @@ -187,9 +187,6 @@ def test_map(idx): ) def test_map_dictlike(idx, mapper): - if isinstance(idx, (pd.CategoricalIndex, pd.IntervalIndex)): - pytest.skip(f"skipping tests for {type(idx)}") - identity = mapper(idx.values, idx) # we don't infer to UInt64 for a dict diff --git a/pandas/tests/io/excel/test_xlrd.py b/pandas/tests/io/excel/test_xlrd.py index 2bb9ba2a397be..2309187b8e9af 100644 --- a/pandas/tests/io/excel/test_xlrd.py +++ b/pandas/tests/io/excel/test_xlrd.py @@ -15,24 +15,35 @@ xlrd = pytest.importorskip("xlrd") xlwt = pytest.importorskip("xlwt") +pytestmark = pytest.mark.filterwarnings( + "ignore:As the xlwt package is no longer maintained:FutureWarning" +) + + +# error: Unsupported operand types for <= ("Version" and "None") +if xlrd_version >= Version("2"): # type: ignore[operator] + exts = [".xls"] +else: + exts = [".xls", ".xlsx", ".xlsm"] + + +@pytest.fixture(params=exts) +def read_ext_xlrd(request): + """ + Valid extensions for reading Excel files with xlrd. -@pytest.fixture(autouse=True) -def skip_ods_and_xlsb_files(read_ext): - if read_ext == ".ods": - pytest.skip("Not valid for xlrd") - if read_ext == ".xlsb": - pytest.skip("Not valid for xlrd") - if read_ext in (".xlsx", ".xlsm") and xlrd_version >= Version("2"): - pytest.skip("Not valid for xlrd >= 2.0") + Similar to read_ext, but excludes .ods, .xlsb, and for xlrd>2 .xlsx, .xlsm + """ + return request.param -def test_read_xlrd_book(read_ext, frame): +def test_read_xlrd_book(read_ext_xlrd, frame): df = frame engine = "xlrd" sheet_name = "SheetA" - with tm.ensure_clean(read_ext) as pth: + with tm.ensure_clean(read_ext_xlrd) as pth: df.to_excel(pth, sheet_name) book = xlrd.open_workbook(pth) diff --git a/pandas/tests/io/parser/common/test_float.py b/pandas/tests/io/parser/common/test_float.py index 0fa85a1f5f8ec..2ca98de914f9e 100644 --- a/pandas/tests/io/parser/common/test_float.py +++ b/pandas/tests/io/parser/common/test_float.py @@ -30,8 +30,6 @@ def test_scientific_no_exponent(all_parsers_all_precisions): df = DataFrame.from_dict({"w": ["2e"], "x": ["3E"], "y": ["42e"], "z": ["632E"]}) data = df.to_csv(index=False) parser, precision = all_parsers_all_precisions - if parser == "pyarrow": - pytest.skip() df_roundtrip = parser.read_csv(StringIO(data), float_precision=precision) tm.assert_frame_equal(df_roundtrip, df) @@ -41,8 +39,7 @@ def test_scientific_no_exponent(all_parsers_all_precisions): def test_very_negative_exponent(all_parsers_all_precisions, neg_exp): # GH#38753 parser, precision = all_parsers_all_precisions - if parser == "pyarrow": - pytest.skip() + data = f"data\n10E{neg_exp}" result = parser.read_csv(StringIO(data), float_precision=precision) expected = DataFrame({"data": [0.0]}) diff --git a/pandas/tests/io/parser/common/test_read_errors.py b/pandas/tests/io/parser/common/test_read_errors.py index a8ea47f4bd9dd..fe00afb4fdc1d 100644 --- a/pandas/tests/io/parser/common/test_read_errors.py +++ b/pandas/tests/io/parser/common/test_read_errors.py @@ -245,7 +245,7 @@ def test_open_file(all_parsers): # GH 39024 parser = all_parsers if parser.engine == "c": - pytest.skip() + pytest.skip("'c' engine does not support sep=None with delim_whitespace=False") with tm.ensure_clean() as path: file = Path(path) diff --git a/pandas/tests/io/parser/test_comment.py b/pandas/tests/io/parser/test_comment.py index e2fd30cb9f2c6..9a14e67c154b6 100644 --- a/pandas/tests/io/parser/test_comment.py +++ b/pandas/tests/io/parser/test_comment.py @@ -30,7 +30,7 @@ def test_comment(all_parsers, na_values): @pytest.mark.parametrize( "read_kwargs", [{}, {"lineterminator": "*"}, {"delim_whitespace": True}] ) -def test_line_comment(all_parsers, read_kwargs): +def test_line_comment(all_parsers, read_kwargs, request): parser = all_parsers data = """# empty A,B,C @@ -42,7 +42,10 @@ def test_line_comment(all_parsers, read_kwargs): data = data.replace(",", " ") elif read_kwargs.get("lineterminator"): if parser.engine != "c": - pytest.skip("Custom terminator not supported with Python engine") + mark = pytest.mark.xfail( + reason="Custom terminator not supported with Python engine" + ) + request.node.add_marker(mark) data = data.replace("\n", read_kwargs.get("lineterminator")) diff --git a/pandas/tests/io/parser/test_encoding.py b/pandas/tests/io/parser/test_encoding.py index 2573314f155cf..993f52b00334f 100644 --- a/pandas/tests/io/parser/test_encoding.py +++ b/pandas/tests/io/parser/test_encoding.py @@ -202,9 +202,6 @@ def test_encoding_named_temp_file(all_parsers): parser = all_parsers encoding = "shift-jis" - if parser.engine == "python": - pytest.skip("NamedTemporaryFile does not work with Python engine") - title = "てすと" data = "こむ" @@ -302,11 +299,15 @@ def test_readcsv_memmap_utf8(all_parsers): tm.assert_frame_equal(df, dfr) -def test_not_readable(all_parsers): +def test_not_readable(all_parsers, request): # GH43439 parser = all_parsers if parser.engine in ("python", "pyarrow"): - pytest.skip("SpooledTemporaryFile does only work with the c-engine") + mark = pytest.mark.xfail( + reason="SpooledTemporaryFile does only work with the c-engine" + ) + request.node.add_marker(mark) + with tempfile.SpooledTemporaryFile() as handle: handle.write(b"abcd") handle.seek(0) diff --git a/pandas/tests/io/parser/test_parse_dates.py b/pandas/tests/io/parser/test_parse_dates.py index 7f7d3a9e17424..68fc86c9586ee 100644 --- a/pandas/tests/io/parser/test_parse_dates.py +++ b/pandas/tests/io/parser/test_parse_dates.py @@ -1709,8 +1709,8 @@ def _helper_hypothesis_delimited_date(call, date_string, **kwargs): def test_hypothesis_delimited_date(date_format, dayfirst, delimiter, test_datetime): if date_format == "%m %Y" and delimiter == ".": pytest.skip( - "parse_datetime_string cannot reliably tell whether \ - e.g. %m.%Y is a float or a date, thus we skip it" + "parse_datetime_string cannot reliably tell whether " + "e.g. %m.%Y is a float or a date, thus we skip it" ) result, expected = None, None except_in_dateutil, except_out_dateutil = None, None diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index 88d4c59ab040d..50d9b75fe9d81 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -595,13 +595,16 @@ def test_write_column_index_nonstring(self, pa): msg = r"parquet must have string column names" self.check_error_on_write(df, engine, ValueError, msg) - def test_use_nullable_dtypes(self, engine): + def test_use_nullable_dtypes(self, engine, request): import pyarrow.parquet as pq if engine == "fastparquet": # We are manually disabling fastparquet's # nullable dtype support pending discussion - pytest.skip("Fastparquet nullable dtype support is disabled") + mark = pytest.mark.xfail( + reason="Fastparquet nullable dtype support is disabled" + ) + request.node.add_marker(mark) table = pyarrow.table( {