From 1dad8d0a256fd0c816f0688edeb56c1edbb6d878 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 18 Mar 2022 17:14:17 -0700 Subject: [PATCH 1/5] TST: Convert skip -> xfail --- pandas/tests/extension/base/methods.py | 2 +- pandas/tests/extension/json/test_json.py | 47 ++++++++++++++---------- pandas/tests/extension/test_sparse.py | 8 ++-- pandas/tests/indexes/test_common.py | 6 ++- pandas/tests/io/excel/test_writers.py | 11 ++++-- pandas/tests/io/formats/test_info.py | 2 +- 6 files changed, 45 insertions(+), 31 deletions(-) diff --git a/pandas/tests/extension/base/methods.py b/pandas/tests/extension/base/methods.py index 6379dfe2efefe..f1ba8ce0fde15 100644 --- a/pandas/tests/extension/base/methods.py +++ b/pandas/tests/extension/base/methods.py @@ -18,7 +18,7 @@ class BaseMethodsTests(BaseExtensionTests): def test_value_counts_default_dropna(self, data): # make sure we have consistent default dropna kwarg if not hasattr(data, "value_counts"): - pytest.skip("value_counts is not implemented") + pytest.skip(f"value_counts is not implemented for {data}") sig = inspect.signature(data.value_counts) kwarg = sig.parameters["dropna"] assert kwarg.default is True diff --git a/pandas/tests/extension/json/test_json.py b/pandas/tests/extension/json/test_json.py index 84491adb30ef6..2b6174be2ca0e 100644 --- a/pandas/tests/extension/json/test_json.py +++ b/pandas/tests/extension/json/test_json.py @@ -190,13 +190,14 @@ def test_series_constructor_scalar_with_index(self, data, dtype): class TestReshaping(BaseJSON, base.BaseReshapingTests): - @pytest.mark.skip(reason="Different definitions of NA") + @pytest.mark.xfail(reason="Different definitions of NA") def test_stack(self): """ The test does .astype(object).stack(). If we happen to have any missing values in `data`, then we'll end up with different rows since we consider `{}` NA, but `.astype(object)` doesn't. """ + super().test_stack() @pytest.mark.xfail(reason="dict for NA") def test_unstack(self, data, index): @@ -214,16 +215,18 @@ class TestIndex(BaseJSON, base.BaseIndexTests): class TestMissing(BaseJSON, base.BaseMissingTests): - @pytest.mark.skip(reason="Setting a dict as a scalar") + @pytest.mark.xfail(reason="Setting a dict as a scalar") def test_fillna_series(self): """We treat dictionaries as a mapping in fillna, not a scalar.""" + super().test_fillna_series() - @pytest.mark.skip(reason="Setting a dict as a scalar") + @pytest.mark.xfail(reason="Setting a dict as a scalar") def test_fillna_frame(self): """We treat dictionaries as a mapping in fillna, not a scalar.""" + super().test_fillna_frame() -unhashable = pytest.mark.skip(reason="Unhashable") +unhashable = pytest.mark.xfail(reason="Unhashable") class TestReduce(base.BaseNoReduceTests): @@ -233,16 +236,16 @@ class TestReduce(base.BaseNoReduceTests): class TestMethods(BaseJSON, base.BaseMethodsTests): @unhashable def test_value_counts(self, all_data, dropna): - pass + super().test_value_counts(all_data, dropna) @unhashable def test_value_counts_with_normalize(self, data): - pass + super().test_value_counts_with_normalize(data) @unhashable def test_sort_values_frame(self): # TODO (EA.factorize): see if _values_for_factorize allows this. - pass + super().test_sort_values_frame() @pytest.mark.parametrize("ascending", [True, False]) def test_sort_values(self, data_for_sorting, ascending, sort_by_key): @@ -256,45 +259,46 @@ def test_sort_values_missing( data_missing_for_sorting, ascending, sort_by_key ) - @pytest.mark.skip(reason="combine for JSONArray not supported") + @pytest.mark.xfail(reason="combine for JSONArray not supported") def test_combine_le(self, data_repeated): - pass + super().test_combine_le(data_repeated) - @pytest.mark.skip(reason="combine for JSONArray not supported") + @pytest.mark.xfail(reason="combine for JSONArray not supported") def test_combine_add(self, data_repeated): - pass + super().test_combine_add(data_repeated) - @pytest.mark.skip(reason="combine for JSONArray not supported") + @pytest.mark.xfail(reason="combine for JSONArray not supported") def test_combine_first(self, data): - pass + super().test_combine_first(data) @unhashable def test_hash_pandas_object_works(self, data, kind): super().test_hash_pandas_object_works(data, kind) - @pytest.mark.skip(reason="broadcasting error") + @pytest.mark.xfail(reason="broadcasting error") def test_where_series(self, data, na_value): # Fails with # *** ValueError: operands could not be broadcast together # with shapes (4,) (4,) (0,) super().test_where_series(data, na_value) - @pytest.mark.skip(reason="Can't compare dicts.") + @pytest.mark.xfail(reason="Can't compare dicts.") def test_searchsorted(self, data_for_sorting): super().test_searchsorted(data_for_sorting) - @pytest.mark.skip(reason="Can't compare dicts.") + @pytest.mark.xfail(reason="Can't compare dicts.") def test_equals(self, data, na_value, as_series): - pass + super().test_equals(data, na_value, as_series) class TestCasting(BaseJSON, base.BaseCastingTests): - @pytest.mark.skip(reason="failing on np.array(self, dtype=str)") + @pytest.mark.xfail(reason="failing on np.array(self, dtype=str)") def test_astype_str(self): """This currently fails in NumPy on np.array(self, dtype=str) with *** ValueError: setting an array element with a sequence """ + super().test_astype_str() # We intentionally don't run base.BaseSetitemTests because pandas' @@ -310,6 +314,7 @@ def test_groupby_extension_transform(self): I think this is what we want, i.e. `.name` should be the original values, and not the values for factorization. """ + super().test_groupby_extension_transform() @unhashable def test_groupby_extension_apply(self): @@ -322,6 +327,7 @@ def test_groupby_extension_apply(self): I suspect that once we support Index[ExtensionArray], we'll be able to dispatch unique. """ + super().test_groupby_extension_apply() @unhashable def test_groupby_extension_agg(self): @@ -329,6 +335,7 @@ def test_groupby_extension_agg(self): This fails when we get to tm.assert_series_equal when left.index contains dictionaries, which are not hashable. """ + super().test_groupby_extension_agg() @unhashable def test_groupby_extension_no_sort(self): @@ -336,6 +343,7 @@ def test_groupby_extension_no_sort(self): This fails when we get to tm.assert_series_equal when left.index contains dictionaries, which are not hashable. """ + super().test_groupby_extension_no_sort() @pytest.mark.xfail(reason="GH#39098: Converts agg result to object") def test_groupby_agg_extension(self, data_for_grouping): @@ -354,10 +362,11 @@ def test_add_series_with_extension_array(self, data): with pytest.raises(TypeError, match="unsupported"): ser + data + @pytest.mark.xfail(reason="not implemented") def test_divmod_series_array(self): # GH 23287 # skipping because it is not implemented - pass + super().test_divmod_series_array() def _check_divmod_op(self, s, op, other, exc=NotImplementedError): return super()._check_divmod_op(s, op, other, exc=TypeError) diff --git a/pandas/tests/extension/test_sparse.py b/pandas/tests/extension/test_sparse.py index dda067ac01e9b..d13f6dab1cc9b 100644 --- a/pandas/tests/extension/test_sparse.py +++ b/pandas/tests/extension/test_sparse.py @@ -266,10 +266,10 @@ def test_fillna_series_method(self, data_missing): with tm.assert_produces_warning(PerformanceWarning): super().test_fillna_limit_backfill(data_missing) - @pytest.mark.skip(reason="Unsupported") + @pytest.mark.xfail(reason="Unsupported") def test_fillna_series(self): # this one looks doable. - pass + super(self).test_fillna_series() def test_fillna_frame(self, data_missing): # Have to override to specify that fill_value will change. @@ -337,9 +337,9 @@ def test_fillna_copy_series(self, data_missing): assert ser._values is not result._values assert ser._values.to_dense() is arr.to_dense() - @pytest.mark.skip(reason="Not Applicable") + @pytest.mark.xfail(reason="Not Applicable") def test_fillna_length_mismatch(self, data_missing): - pass + super().test_fillna_length_mismatch(data_missing) def test_where_series(self, data, na_value): assert data[0] != data[1] diff --git a/pandas/tests/indexes/test_common.py b/pandas/tests/indexes/test_common.py index 31e82545646b5..a6b583a6f2e9d 100644 --- a/pandas/tests/indexes/test_common.py +++ b/pandas/tests/indexes/test_common.py @@ -454,12 +454,14 @@ def test_sort_values_invalid_na_position(index_with_missing, na_position): @pytest.mark.parametrize("na_position", ["first", "last"]) -def test_sort_values_with_missing(index_with_missing, na_position): +def test_sort_values_with_missing(index_with_missing, na_position, request): # GH 35584. Test that sort_values works with missing values, # sort non-missing and place missing according to na_position if isinstance(index_with_missing, CategoricalIndex): - pytest.skip("missing value sorting order not well-defined") + request.node.add_marker( + pytest.mark.xfail(reason="missing value sorting order not well-defined") + ) missing_count = np.sum(index_with_missing.isna()) not_na_vals = index_with_missing[index_with_missing.notna()].values diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index 5b46c0baac165..e68bb67495a92 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -1087,7 +1087,7 @@ def test_comment_empty_line(self, path): result = pd.read_excel(path, comment="#") tm.assert_frame_equal(result, expected) - def test_datetimes(self, path): + def test_datetimes(self, path, request): # Test writing and reading datetimes. For issue #9139. (xref #9185) datetimes = [ @@ -1107,9 +1107,12 @@ def test_datetimes(self, path): write_frame = DataFrame({"A": datetimes}) write_frame.to_excel(path, "Sheet1") if path.endswith("xlsx") or path.endswith("xlsm"): - pytest.skip( - "Defaults to openpyxl and fails with floating point error on " - "datetimes; may be fixed on newer versions of openpyxl - GH #38644" + request.node.add_marker( + pytest.mark.xfail( + reason="Defaults to openpyxl and fails with " + "floating point error on datetimes; may be fixed on " + "newer versions of openpyxl - GH #38644" + ) ) read_frame = pd.read_excel(path, sheet_name="Sheet1", header=0) diff --git a/pandas/tests/io/formats/test_info.py b/pandas/tests/io/formats/test_info.py index 6bcf971e5bb05..54b5e699cd034 100644 --- a/pandas/tests/io/formats/test_info.py +++ b/pandas/tests/io/formats/test_info.py @@ -388,7 +388,7 @@ def test_info_memory_usage_deep_not_pypy(): assert df_object.memory_usage(deep=True).sum() > df_object.memory_usage().sum() -@pytest.mark.skipif(not PYPY, reason="on PyPy deep=True does not change result") +@pytest.mark.xfail(not PYPY, reason="on PyPy deep=True does not change result") def test_info_memory_usage_deep_pypy(): df_with_object_index = DataFrame({"a": [1]}, index=["foo"]) assert ( From 45e6c6e49838f6f1f829b14e5ca03e98a57823f5 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 18 Mar 2022 19:53:58 -0700 Subject: [PATCH 2/5] Fix xpass and repr --- pandas/tests/extension/base/methods.py | 2 +- pandas/tests/io/excel/test_writers.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pandas/tests/extension/base/methods.py b/pandas/tests/extension/base/methods.py index f1ba8ce0fde15..b829b017d5fb1 100644 --- a/pandas/tests/extension/base/methods.py +++ b/pandas/tests/extension/base/methods.py @@ -18,7 +18,7 @@ class BaseMethodsTests(BaseExtensionTests): def test_value_counts_default_dropna(self, data): # make sure we have consistent default dropna kwarg if not hasattr(data, "value_counts"): - pytest.skip(f"value_counts is not implemented for {data}") + pytest.skip(f"value_counts is not implemented for {type(data)}") sig = inspect.signature(data.value_counts) kwarg = sig.parameters["dropna"] assert kwarg.default is True diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index e68bb67495a92..47427b5a7d115 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -21,6 +21,7 @@ option_context, ) import pandas._testing as tm +from pandas.util.version import Version from pandas.io.excel import ( ExcelFile, @@ -1088,7 +1089,7 @@ def test_comment_empty_line(self, path): tm.assert_frame_equal(result, expected) def test_datetimes(self, path, request): - + openpyxl = pytest.importorskip("openpyxl") # Test writing and reading datetimes. For issue #9139. (xref #9185) datetimes = [ datetime(2013, 1, 13, 1, 2, 3), @@ -1106,7 +1107,11 @@ def test_datetimes(self, path, request): write_frame = DataFrame({"A": datetimes}) write_frame.to_excel(path, "Sheet1") - if path.endswith("xlsx") or path.endswith("xlsm"): + if ( + path.endswith("xlsx") + or path.endswith("xlsm") + and Version(openpyxl.__version__) > Version("3.0.6") + ): request.node.add_marker( pytest.mark.xfail( reason="Defaults to openpyxl and fails with " From b0c31d21bb23d9ac9540f6e387cf7ceab559bb7d Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 19 Mar 2022 12:03:25 -0700 Subject: [PATCH 3/5] Fix conditions --- pandas/tests/extension/json/test_json.py | 4 +++- pandas/tests/io/excel/test_writers.py | 8 +++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/tests/extension/json/test_json.py b/pandas/tests/extension/json/test_json.py index 2b6174be2ca0e..fe4a5f63759cc 100644 --- a/pandas/tests/extension/json/test_json.py +++ b/pandas/tests/extension/json/test_json.py @@ -4,6 +4,8 @@ import pytest +from pandas.compat import PY310 + import pandas as pd import pandas._testing as tm from pandas.tests.extension import base @@ -267,7 +269,7 @@ def test_combine_le(self, data_repeated): def test_combine_add(self, data_repeated): super().test_combine_add(data_repeated) - @pytest.mark.xfail(reason="combine for JSONArray not supported") + @pytest.mark.xfail(not PY310, reason="combine for JSONArray not supported") def test_combine_first(self, data): super().test_combine_first(data) diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index 47427b5a7d115..59debcd107fac 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -1107,11 +1107,9 @@ def test_datetimes(self, path, request): write_frame = DataFrame({"A": datetimes}) write_frame.to_excel(path, "Sheet1") - if ( - path.endswith("xlsx") - or path.endswith("xlsm") - and Version(openpyxl.__version__) > Version("3.0.6") - ): + if (path.endswith("xlsx") or path.endswith("xlsm")) and Version( + openpyxl.__version__ + ) > Version("3.0.6"): request.node.add_marker( pytest.mark.xfail( reason="Defaults to openpyxl and fails with " From 40a7c9c8da454a867fe1d37cf6f63b6e1869fe9d Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 19 Mar 2022 15:11:42 -0700 Subject: [PATCH 4/5] Tweak again --- pandas/tests/extension/json/test_json.py | 4 +--- pandas/tests/io/excel/test_writers.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/tests/extension/json/test_json.py b/pandas/tests/extension/json/test_json.py index fe4a5f63759cc..2b6174be2ca0e 100644 --- a/pandas/tests/extension/json/test_json.py +++ b/pandas/tests/extension/json/test_json.py @@ -4,8 +4,6 @@ import pytest -from pandas.compat import PY310 - import pandas as pd import pandas._testing as tm from pandas.tests.extension import base @@ -269,7 +267,7 @@ def test_combine_le(self, data_repeated): def test_combine_add(self, data_repeated): super().test_combine_add(data_repeated) - @pytest.mark.xfail(not PY310, reason="combine for JSONArray not supported") + @pytest.mark.xfail(reason="combine for JSONArray not supported") def test_combine_first(self, data): super().test_combine_first(data) diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index 59debcd107fac..06c106ed22329 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -1109,7 +1109,7 @@ def test_datetimes(self, path, request): write_frame.to_excel(path, "Sheet1") if (path.endswith("xlsx") or path.endswith("xlsm")) and Version( openpyxl.__version__ - ) > Version("3.0.6"): + ) < Version("3.0.6"): request.node.add_marker( pytest.mark.xfail( reason="Defaults to openpyxl and fails with " From 9459aafa4f94ed5d66799c004a716b6b9247fbae Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 19 Mar 2022 18:21:16 -0700 Subject: [PATCH 5/5] strict=False since sometimes passes --- pandas/tests/indexes/test_common.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexes/test_common.py b/pandas/tests/indexes/test_common.py index a6b583a6f2e9d..05c66191ca3a2 100644 --- a/pandas/tests/indexes/test_common.py +++ b/pandas/tests/indexes/test_common.py @@ -460,7 +460,9 @@ def test_sort_values_with_missing(index_with_missing, na_position, request): if isinstance(index_with_missing, CategoricalIndex): request.node.add_marker( - pytest.mark.xfail(reason="missing value sorting order not well-defined") + pytest.mark.xfail( + reason="missing value sorting order not well-defined", strict=False + ) ) missing_count = np.sum(index_with_missing.isna())