From 86064ff7547ccfea0beed429e0363ee5c128378d Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 16 Dec 2021 12:24:41 -0800 Subject: [PATCH] TST: skip fewer tests (#44918) --- ci/deps/actions-38-db.yaml | 2 +- environment.yml | 2 +- pandas/conftest.py | 15 +++++++++++++++ pandas/core/arrays/categorical.py | 4 ++-- pandas/tests/base/test_fillna.py | 20 ++++++++++---------- pandas/tests/base/test_unique.py | 4 ++-- pandas/tests/extension/base/dim2.py | 15 +++------------ pandas/tests/indexes/test_common.py | 8 ++++++-- pandas/tests/indexes/test_setops.py | 24 ++++++++---------------- pandas/tests/io/excel/test_writers.py | 12 ++++++++---- pandas/tests/io/formats/test_to_csv.py | 3 --- pandas/tests/io/json/test_compression.py | 3 --- pandas/tests/io/json/test_pandas.py | 3 +-- pandas/tests/series/methods/test_rank.py | 8 ++++---- pandas/tests/test_algos.py | 6 +++++- 15 files changed, 66 insertions(+), 63 deletions(-) diff --git a/ci/deps/actions-38-db.yaml b/ci/deps/actions-38-db.yaml index 1a4e5d12f70df..c08c642049b41 100644 --- a/ci/deps/actions-38-db.yaml +++ b/ci/deps/actions-38-db.yaml @@ -12,7 +12,7 @@ dependencies: - pytest-cov>=2.10.1 # this is only needed in the coverage build, ref: GH 35737 # pandas dependencies - - aiobotocore<2.0.0 + - aiobotocore<2.0.0 # GH#44311 pinned to fix docbuild - beautifulsoup4 - boto3 - botocore>=1.11 diff --git a/environment.yml b/environment.yml index b4a8b977359cb..30d05ab7700ff 100644 --- a/environment.yml +++ b/environment.yml @@ -105,7 +105,7 @@ dependencies: - pytables>=3.6.1 # pandas.read_hdf, DataFrame.to_hdf - s3fs>=0.4.0 # file IO when using 's3://...' path - - aiobotocore<2.0.0 + - aiobotocore<2.0.0 # GH#44311 pinned to fix docbuild - fsspec>=0.7.4 # for generic remote file operations - gcsfs>=0.6.0 # file IO when using 'gcs://...' path - sqlalchemy # pandas.read_sql, DataFrame.to_sql diff --git a/pandas/conftest.py b/pandas/conftest.py index 7ea0df550f1f4..8c870bc98b5ff 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -559,6 +559,21 @@ def index_flat(request): index_flat2 = index_flat +@pytest.fixture( + params=[ + key + for key in indices_dict + if not isinstance(indices_dict[key], MultiIndex) and indices_dict[key].is_unique + ] +) +def index_flat_unique(request): + """ + index_flat with uniqueness requirement. + """ + key = request.param + return indices_dict[key].copy() + + @pytest.fixture( params=[ key diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 67dc6ade25254..62e66732edd9c 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -2377,7 +2377,7 @@ def describe(self): return result - def isin(self, values) -> np.ndarray: + def isin(self, values) -> npt.NDArray[np.bool_]: """ Check whether `values` are contained in Categorical. @@ -2394,7 +2394,7 @@ def isin(self, values) -> np.ndarray: Returns ------- - isin : numpy.ndarray (bool dtype) + np.ndarray[bool] Raises ------ diff --git a/pandas/tests/base/test_fillna.py b/pandas/tests/base/test_fillna.py index 32c9d288e665d..7300d3013305a 100644 --- a/pandas/tests/base/test_fillna.py +++ b/pandas/tests/base/test_fillna.py @@ -6,9 +6,7 @@ import numpy as np import pytest -from pandas.core.dtypes.generic import ABCMultiIndex - -from pandas import Index +from pandas import MultiIndex import pandas._testing as tm from pandas.tests.base.common import allow_na_ops @@ -16,16 +14,18 @@ def test_fillna(index_or_series_obj): # GH 11343 obj = index_or_series_obj - if isinstance(obj, ABCMultiIndex): - pytest.skip("MultiIndex doesn't support isna") + + if isinstance(obj, MultiIndex): + msg = "isna is not defined for MultiIndex" + with pytest.raises(NotImplementedError, match=msg): + obj.fillna(0) + return # values will not be changed fill_value = obj.values[0] if len(obj) > 0 else 0 result = obj.fillna(fill_value) - if isinstance(obj, Index): - tm.assert_index_equal(obj, result) - else: - tm.assert_series_equal(obj, result) + + tm.assert_equal(obj, result) # check shallow_copied assert obj is not result @@ -41,7 +41,7 @@ def test_fillna_null(null_obj, index_or_series_obj): pytest.skip(f"{klass} doesn't allow for NA operations") elif len(obj) < 1: pytest.skip("Test doesn't make sense on empty data") - elif isinstance(obj, ABCMultiIndex): + elif isinstance(obj, MultiIndex): pytest.skip(f"MultiIndex can't hold '{null_obj}'") values = obj._values diff --git a/pandas/tests/base/test_unique.py b/pandas/tests/base/test_unique.py index 31f2aebcba4ba..59c1c61a4c8cc 100644 --- a/pandas/tests/base/test_unique.py +++ b/pandas/tests/base/test_unique.py @@ -123,6 +123,6 @@ def test_unique_bad_unicode(index_or_series): @pytest.mark.parametrize("dropna", [True, False]) def test_nunique_dropna(dropna): # GH37566 - s = pd.Series(["yes", "yes", pd.NA, np.nan, None, pd.NaT]) - res = s.nunique(dropna) + ser = pd.Series(["yes", "yes", pd.NA, np.nan, None, pd.NaT]) + res = ser.nunique(dropna) assert res == 1 if dropna else 5 diff --git a/pandas/tests/extension/base/dim2.py b/pandas/tests/extension/base/dim2.py index d86d43b0ef9e6..a201366152c2f 100644 --- a/pandas/tests/extension/base/dim2.py +++ b/pandas/tests/extension/base/dim2.py @@ -150,10 +150,7 @@ def test_fillna_2d_method(self, data_missing, method): self.assert_extension_array_equal(result, expected) @pytest.mark.parametrize("method", ["mean", "median", "var", "std", "sum", "prod"]) - def test_reductions_2d_axis_none(self, data, method, request): - if not hasattr(data, method): - pytest.skip("test is not applicable for this type/dtype") - + def test_reductions_2d_axis_none(self, data, method): arr2d = data.reshape(1, -1) err_expected = None @@ -178,10 +175,7 @@ def test_reductions_2d_axis_none(self, data, method, request): assert is_matching_na(result, expected) or result == expected @pytest.mark.parametrize("method", ["mean", "median", "var", "std", "sum", "prod"]) - def test_reductions_2d_axis0(self, data, method, request): - if not hasattr(data, method): - pytest.skip("test is not applicable for this type/dtype") - + def test_reductions_2d_axis0(self, data, method): arr2d = data.reshape(1, -1) kwargs = {} @@ -231,10 +225,7 @@ def get_reduction_result_dtype(dtype): # punt on method == "var" @pytest.mark.parametrize("method", ["mean", "median", "var", "std", "sum", "prod"]) - def test_reductions_2d_axis1(self, data, method, request): - if not hasattr(data, method): - pytest.skip("test is not applicable for this type/dtype") - + def test_reductions_2d_axis1(self, data, method): arr2d = data.reshape(1, -1) try: diff --git a/pandas/tests/indexes/test_common.py b/pandas/tests/indexes/test_common.py index fff11583e5161..0407dc02833fd 100644 --- a/pandas/tests/indexes/test_common.py +++ b/pandas/tests/indexes/test_common.py @@ -244,13 +244,17 @@ def test_unique(self, index_flat): result = i.unique() tm.assert_index_equal(result, expected) - def test_searchsorted_monotonic(self, index_flat): + def test_searchsorted_monotonic(self, index_flat, request): # GH17271 index = index_flat # not implemented for tuple searches in MultiIndex # or Intervals searches in IntervalIndex if isinstance(index, pd.IntervalIndex): - pytest.skip("Skip check for MultiIndex/IntervalIndex") + mark = pytest.mark.xfail( + reason="IntervalIndex.searchsorted does not support Interval arg", + raises=NotImplementedError, + ) + request.node.add_marker(mark) # nothing to test if the index is empty if index.empty: diff --git a/pandas/tests/indexes/test_setops.py b/pandas/tests/indexes/test_setops.py index b3c86f91927ee..648b79bd288df 100644 --- a/pandas/tests/indexes/test_setops.py +++ b/pandas/tests/indexes/test_setops.py @@ -272,13 +272,11 @@ def test_symmetric_difference(self, index): (None, None, None), ], ) - def test_corner_union(self, index_flat, fname, sname, expected_name): + def test_corner_union(self, index_flat_unique, fname, sname, expected_name): # GH#9943, GH#9862 # Test unions with various name combinations # Do not test MultiIndex or repeats - index = index_flat - if not index.is_unique: - pytest.skip("Not for MultiIndex or repeated indices") + index = index_flat_unique # Test copy.union(copy) first = index.copy().set_names(fname) @@ -318,10 +316,8 @@ def test_corner_union(self, index_flat, fname, sname, expected_name): (None, None, None), ], ) - def test_union_unequal(self, index_flat, fname, sname, expected_name): - index = index_flat - if not index.is_unique: - pytest.skip("Not for MultiIndex or repeated indices") + def test_union_unequal(self, index_flat_unique, fname, sname, expected_name): + index = index_flat_unique # test copy.union(subset) - need sort for unicode and string first = index.copy().set_names(fname) @@ -340,12 +336,10 @@ def test_union_unequal(self, index_flat, fname, sname, expected_name): (None, None, None), ], ) - def test_corner_intersect(self, index_flat, fname, sname, expected_name): + def test_corner_intersect(self, index_flat_unique, fname, sname, expected_name): # GH#35847 # Test intersections with various name combinations - index = index_flat - if not index.is_unique: - pytest.skip("Not for MultiIndex or repeated indices") + index = index_flat_unique # Test copy.intersection(copy) first = index.copy().set_names(fname) @@ -385,10 +379,8 @@ def test_corner_intersect(self, index_flat, fname, sname, expected_name): (None, None, None), ], ) - def test_intersect_unequal(self, index_flat, fname, sname, expected_name): - index = index_flat - if not index.is_unique: - pytest.skip("Not for MultiIndex or repeated indices") + def test_intersect_unequal(self, index_flat_unique, fname, sname, expected_name): + index = index_flat_unique # test copy.intersection(subset) - need sort for unicode and string first = index.copy().set_names(fname) diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index 8291d0c85b50d..0315783569c23 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -207,14 +207,18 @@ def test_read_excel_multiindex_empty_level(self, ext): @pytest.mark.parametrize("c_idx_levels", [1, 3]) @pytest.mark.parametrize("r_idx_levels", [1, 3]) def test_excel_multindex_roundtrip( - self, ext, c_idx_names, r_idx_names, c_idx_levels, r_idx_levels + self, ext, c_idx_names, r_idx_names, c_idx_levels, r_idx_levels, request ): # see gh-4679 with tm.ensure_clean(ext) as pth: - if c_idx_levels == 1 and c_idx_names: - pytest.skip( - "Column index name cannot be serialized unless it's a MultiIndex" + if (c_idx_levels == 1 and c_idx_names) and not ( + r_idx_levels == 3 and not r_idx_names + ): + mark = pytest.mark.xfail( + reason="Column index name cannot be serialized unless " + "it's a MultiIndex" ) + request.node.add_marker(mark) # Empty name case current read in as # unnamed levels, not Nones. diff --git a/pandas/tests/io/formats/test_to_csv.py b/pandas/tests/io/formats/test_to_csv.py index 059fd96db43ad..8815423d95d65 100644 --- a/pandas/tests/io/formats/test_to_csv.py +++ b/pandas/tests/io/formats/test_to_csv.py @@ -498,9 +498,6 @@ def test_to_csv_compression(self, compression_only, read_infer, to_infer): # see gh-15008 compression = compression_only - if compression == "zip": - pytest.skip(f"{compression} is not supported for to_csv") - # We'll complete file extension subsequently. filename = "test." diff --git a/pandas/tests/io/json/test_compression.py b/pandas/tests/io/json/test_compression.py index febeb4d690562..e0136520bdeb5 100644 --- a/pandas/tests/io/json/test_compression.py +++ b/pandas/tests/io/json/test_compression.py @@ -95,9 +95,6 @@ def test_to_json_compression(compression_only, read_infer, to_infer): # see gh-15008 compression = compression_only - if compression == "zip": - pytest.skip(f"{compression} is not supported for to_csv") - # We'll complete file extension subsequently. filename = "test." diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 522031f466be3..10eb3526c80ff 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1323,10 +1323,9 @@ def test_to_jsonl(self): tm.assert_frame_equal(read_json(result, lines=True), df) # TODO: there is a near-identical test for pytables; can we share? + @pytest.mark.xfail(reason="GH#13774 encoding kwarg not supported", raises=TypeError) def test_latin_encoding(self): # GH 13774 - pytest.skip("encoding not implemented in .to_json(), xref #13774") - values = [ [b"E\xc9, 17", b"", b"a", b"b", b"c"], [b"E\xc9, 17", b"a", b"b", b"c"], diff --git a/pandas/tests/series/methods/test_rank.py b/pandas/tests/series/methods/test_rank.py index 088e10b0ba070..43b210a50dab2 100644 --- a/pandas/tests/series/methods/test_rank.py +++ b/pandas/tests/series/methods/test_rank.py @@ -33,9 +33,9 @@ class TestSeriesRank: "dense": np.array([1, 3, 4, 2, np.nan, 2, 1, 5, np.nan, 3]), } + @td.skip_if_no_scipy def test_rank(self, datetime_series): - pytest.importorskip("scipy.stats.special") - rankdata = pytest.importorskip("scipy.stats.rankdata") + from scipy.stats import rankdata datetime_series[::2] = np.nan datetime_series[:10][::3] = 4.0 @@ -280,9 +280,9 @@ def test_rank_desc_mix_nans_infs(self): exp = Series([3, np.nan, 1, 4, 2], dtype="float64") tm.assert_series_equal(result, exp) + @td.skip_if_no_scipy def test_rank_methods_series(self): - pytest.importorskip("scipy.stats.special") - rankdata = pytest.importorskip("scipy.stats.rankdata") + from scipy.stats import rankdata xs = np.random.randn(9) xs = np.concatenate([xs[i:] for i in range(0, 9, 2)]) # add duplicates diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index 1345a66673d1c..f4eb08582bc80 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -509,7 +509,8 @@ def test_on_index_object(self): def test_dtype_preservation(self, any_numpy_dtype): # GH 15442 if any_numpy_dtype in (tm.BYTES_DTYPES + tm.STRING_DTYPES): - pytest.skip("skip string dtype") + data = [1, 2, 2] + uniques = [1, 2] elif is_integer_dtype(any_numpy_dtype): data = [1, 2, 2] uniques = [1, 2] @@ -533,6 +534,9 @@ def test_dtype_preservation(self, any_numpy_dtype): result = Series(data, dtype=any_numpy_dtype).unique() expected = np.array(uniques, dtype=any_numpy_dtype) + if any_numpy_dtype in tm.STRING_DTYPES: + expected = expected.astype(object) + tm.assert_numpy_array_equal(result, expected) def test_datetime64_dtype_array_returned(self):