Skip to content

TST: More explicit test patterns #54463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pandas/tests/arithmetic/test_datetime64.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,7 @@ def test_dti_cmp_datetimelike(self, other, tz_naive_fixture):
dti = date_range("2016-01-01", periods=2, tz=tz)
if tz is not None:
if isinstance(other, np.datetime64):
# no tzaware version available
return
pytest.skip("no tzaware version available")
other = localize_pydatetime(other, dti.tzinfo)

result = dti == other
Expand Down Expand Up @@ -1080,13 +1079,14 @@ def test_dt64arr_add_dtlike_raises(self, tz_naive_fixture, box_with_array):
@pytest.mark.parametrize("freq", ["H", "D", "W", "M", "MS", "Q", "B", None])
@pytest.mark.parametrize("dtype", [None, "uint8"])
def test_dt64arr_addsub_intlike(
self, dtype, box_with_array, freq, tz_naive_fixture
self, request, dtype, box_with_array, freq, tz_naive_fixture
):
# GH#19959, GH#19123, GH#19012
tz = tz_naive_fixture
if box_with_array is pd.DataFrame:
# alignment headaches
return
request.node.add_marker(
pytest.mark.xfail(raises=ValueError, reason="Axis alignment fails")
)

if freq is None:
dti = DatetimeIndex(["NaT", "2017-04-05 06:07:08"], tz=tz)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arithmetic/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def test_divmod_zero(self, zero, numeric_idx):
def test_div_negative_zero(self, zero, numeric_idx, op):
# Check that -1 / -0.0 returns np.inf, not -np.inf
if numeric_idx.dtype == np.uint64:
return
pytest.skip(f"Not relevant for {numeric_idx.dtype}")
idx = numeric_idx - 3

expected = Index([-np.inf, -np.inf, -np.inf, np.nan, np.inf], dtype=np.float64)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arithmetic/test_timedelta64.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ def test_td64arr_add_sub_datetimelike_scalar(
ts = dt_scalar.to_pydatetime()
elif cls is np.datetime64:
if tz_naive_fixture is not None:
return
pytest.skip(f"{cls} doesn support {tz_naive_fixture}")
ts = dt_scalar.to_datetime64()
else:
ts = dt_scalar
Expand Down
5 changes: 1 addition & 4 deletions pandas/tests/frame/methods/test_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,7 @@ def create_cols(name):

# add in some nans
df_float.iloc[30:50, 1:3] = np.nan

# ## this is a bug in read_csv right now ####
# df_dt.loc[30:50,1:3] = np.nan
# FIXME: don't leave commented-out
df_dt.iloc[30:50, 1:3] = np.nan

df = pd.concat([df_float, df_int, df_bool, df_object, df_dt], axis=1)

Expand Down
10 changes: 6 additions & 4 deletions pandas/tests/frame/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,12 @@ def test_inplace_ops_identity(self):
[
"add",
"and",
"div",
pytest.param(
"div",
marks=pytest.mark.xfail(
raises=AttributeError, reason="__idiv__ not implemented"
),
),
"floordiv",
"mod",
"mul",
Expand All @@ -1778,9 +1783,6 @@ def test_inplace_ops_identity(self):
],
)
def test_inplace_ops_identity2(self, op):
if op == "div":
return

df = DataFrame({"a": [1.0, 2.0, 3.0], "b": [1, 2, 3]})

operand = 2
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2514,7 +2514,7 @@ def test_dict_nocopy(
b = np.array([3, 4], dtype=any_numpy_dtype)
if b.dtype.kind in ["S", "U"]:
# These get cast, making the checks below more cumbersome
return
pytest.skip(f"{b.dtype} get cast, making the checks below more cumbersome")

c = pd.array([1, 2], dtype=any_numeric_ea_dtype)
c_orig = c.copy()
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/groupby/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ def test_frame_consistency(groupby_func):
def test_series_consistency(request, groupby_func):
# GH#48028
if groupby_func in ("first", "last"):
# first and last are entirely different between Series and groupby
return
pytest.skip("first and last are entirely different between Series and groupby")

if groupby_func in ("cumcount", "corrwith", "ngroup"):
assert not hasattr(Series, groupby_func)
Expand Down
11 changes: 5 additions & 6 deletions pandas/tests/groupby/transform/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,9 +775,8 @@ def frame_mi(frame):
{"by": np.random.default_rng(2).integers(0, 50, size=10).astype(float)},
{"level": 0},
{"by": "string"},
# {"by": 'string_missing'}]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no string_missing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks added it back

# {"by": ['int','string']}]:
# TODO: remove or enable commented-out code
pytest.param({"by": "string_missing"}, marks=pytest.mark.xfail),
{"by": ["int", "string"]},
],
)
def test_cython_transform_frame(request, op, args, targop, df_fix, gb_target):
Expand Down Expand Up @@ -825,9 +824,9 @@ def test_cython_transform_frame(request, op, args, targop, df_fix, gb_target):
{"by": np.random.default_rng(2).integers(0, 50, size=10).astype(float)},
{"level": 0},
{"by": "string"},
# {"by": 'string_missing'}]:
# {"by": ['int','string']}]:
# TODO: remove or enable commented-out code
# TODO: create xfail condition given other params
# {"by": 'string_missing'},
{"by": ["int", "string"]},
],
)
@pytest.mark.parametrize(
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/indexes/multi/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,7 @@ def test_union_with_duplicates_keep_ea_dtype(dupe_val, any_numeric_ea_dtype):
def test_union_duplicates(index, request):
# GH#38977
if index.empty or isinstance(index, (IntervalIndex, CategoricalIndex)):
# No duplicates in empty indexes
return
pytest.skip(f"No duplicates in an empty {type(index).__name__}")

values = index.unique().values.tolist()
mi1 = MultiIndex.from_arrays([values, [1] * len(values)])
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/test_any_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_hash_error(index):

def test_mutability(index):
if not len(index):
return
pytest.skip("Test doesn't make sense for empty index")
msg = "Index does not support mutable operations"
with pytest.raises(TypeError, match=msg):
index[0] = index[0]
Expand Down
8 changes: 3 additions & 5 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,9 @@ def test_map_dictlike_simple(self, mapper):
def test_map_dictlike(self, index, mapper, request):
# GH 12756
if isinstance(index, CategoricalIndex):
# Tested in test_categorical
return
pytest.skip("Tested in test_categorical")
elif not index.is_unique:
# Cannot map duplicated index
return
pytest.skip("Cannot map duplicated index")

rng = np.arange(len(index), 0, -1, dtype=np.int64)

Expand Down Expand Up @@ -785,7 +783,7 @@ def test_drop_tuple(self, values, to_drop):
def test_drop_with_duplicates_in_index(self, index):
# GH38051
if len(index) == 0 or isinstance(index, MultiIndex):
return
pytest.skip("Test doesn't make sense for empty MultiIndex")
if isinstance(index, IntervalIndex) and not IS64:
pytest.skip("Cannot test IntervalIndex with int64 dtype on 32 bit platform")
index = index.unique().repeat(2)
Expand Down
10 changes: 6 additions & 4 deletions pandas/tests/indexes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ def test_set_name_methods(self, index_flat):
assert res is None
assert index.name == new_name
assert index.names == [new_name]
# FIXME: dont leave commented-out
# with pytest.raises(TypeError, match="list-like"):
# # should still fail even if it would be the right length
# ind.set_names("a")
with pytest.raises(ValueError, match="Level must be None"):
index.set_names("a", level=0)

Expand All @@ -134,6 +130,12 @@ def test_set_name_methods(self, index_flat):
assert index.name == name
assert index.names == [name]

@pytest.mark.xfail
def test_set_names_single_label_no_level(self, index_flat):
with pytest.raises(TypeError, match="list-like"):
# should still fail even if it would be the right length
index_flat.set_names("a")

def test_copy_and_deepcopy(self, index_flat):
index = index_flat

Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/indexes/test_index_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ def test_constructor_infer_nat_dt_like(
):
if isinstance(nulls_fixture, Decimal):
# We dont cast these to datetime64/timedelta64
return
pytest.skip(
f"We don't cast {type(nulls_fixture).__name__} to "
"datetime64/timedelta64"
)

expected = klass([NaT, NaT])
assert expected.dtype == dtype
Expand Down
7 changes: 3 additions & 4 deletions pandas/tests/indexes/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ def test_take_invalid_kwargs(self, index):
def test_take(self, index):
indexer = [4, 3, 0, 2]
if len(index) < 5:
# not enough elements; ignore
return
pytest.skip("Test doesn't make sense since not enough elements")

result = index.take(indexer)
expected = index[indexer]
Expand All @@ -81,7 +80,7 @@ def test_take_minus1_without_fill(self, index):
# -1 does not get treated as NA unless allow_fill=True is passed
if len(index) == 0:
# Test is not applicable
return
pytest.skip("Test doesn't make sense for empty index")

result = index.take([0, 0, -1])

Expand Down Expand Up @@ -289,7 +288,7 @@ class TestPutmask:
def test_putmask_with_wrong_mask(self, index):
# GH#18368
if not len(index):
return
pytest.skip("Test doesn't make sense for empty index")

fill = index[0]

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/test_numpy_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_numpy_ufuncs_other(index, func):
def test_numpy_ufuncs_reductions(index, func, request):
# TODO: overlap with tests.series.test_ufunc.test_reductions
if len(index) == 0:
return
pytest.skip("Test doesn't make sense for empty index.")

if isinstance(index, CategoricalIndex) and index.dtype.ordered is False:
with pytest.raises(TypeError, match="is not ordered for"):
Expand Down
39 changes: 15 additions & 24 deletions pandas/tests/indexes/test_old_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_numeric_compat(self, simple_index):
# we can remove multi.test_compat.test_numeric_compat
assert not isinstance(idx, MultiIndex)
if type(idx) is Index:
return
pytest.skip("Not applicable for Index")
if is_numeric_dtype(simple_index.dtype) or isinstance(
simple_index, TimedeltaIndex
):
Expand Down Expand Up @@ -246,9 +246,10 @@ def test_ensure_copied_data(self, index):
# Needs "freq" specification:
init_kwargs["freq"] = index.freq
elif isinstance(index, (RangeIndex, MultiIndex, CategoricalIndex)):
# RangeIndex cannot be initialized from data
# MultiIndex and CategoricalIndex are tested separately
return
pytest.skip(
"RangeIndex cannot be initialized from data, "
"MultiIndex and CategoricalIndex are tested separately"
)
elif index.dtype == object and index.inferred_type == "boolean":
init_kwargs["dtype"] = index.dtype

Expand Down Expand Up @@ -319,9 +320,8 @@ def test_memory_usage(self, index):
assert result3 > result2

def test_argsort(self, index):
# separately tested
if isinstance(index, CategoricalIndex):
return
pytest.skip(f"{type(self).__name__} separately tested")

result = index.argsort()
expected = np.array(index).argsort()
Expand Down Expand Up @@ -400,7 +400,7 @@ def test_insert_base(self, index):
result = index[1:4]

if not len(index):
return
pytest.skip("Not applicable for empty index")

# test 0th element
assert index[0:4].equals(result.insert(0, index[0]))
Expand Down Expand Up @@ -434,11 +434,11 @@ def test_insert_out_of_bounds(self, index):

def test_delete_base(self, index):
if not len(index):
return
pytest.skip("Not applicable for empty index")

if isinstance(index, RangeIndex):
# tested in class
return
pytest.skip(f"{type(self).__name__} tested elsewhere")

expected = index[1:]
result = index.delete(0)
Expand All @@ -458,9 +458,7 @@ def test_delete_base(self, index):
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
def test_equals(self, index):
if isinstance(index, IntervalIndex):
# IntervalIndex tested separately, the index.equals(index.astype(object))
# fails for IntervalIndex
return
pytest.skip(f"{type(index).__name__} tested elsewhere")

is_ea_idx = type(index) is Index and not isinstance(index.dtype, np.dtype)

Expand Down Expand Up @@ -566,12 +564,11 @@ def test_format_empty(self, simple_index):
def test_fillna(self, index):
# GH 11343
if len(index) == 0:
return
pytest.skip("Not relevant for empty index")
elif index.dtype == bool:
# can't hold NAs
return
pytest.skip(f"{index.dtype} cannot hold NAs")
elif isinstance(index, Index) and is_integer_dtype(index.dtype):
return
pytest.skip(f"Not relevant for Index with {index.dtype}")
elif isinstance(index, MultiIndex):
idx = index.copy(deep=True)
msg = "isna is not defined for MultiIndex"
Expand Down Expand Up @@ -654,15 +651,9 @@ def test_map(self, simple_index):
],
)
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
def test_map_dictlike(self, mapper, simple_index):
def test_map_dictlike(self, mapper, simple_index, request):
idx = simple_index
if isinstance(idx, CategoricalIndex):
# FIXME: this fails with CategoricalIndex bc it goes through
# Categorical.map which ends up calling get_indexer with
# non-unique values, which raises. This _should_ work fine for
# CategoricalIndex.
pytest.skip(f"skipping tests for {type(idx)}")
elif isinstance(idx, (DatetimeIndex, TimedeltaIndex, PeriodIndex)):
if isinstance(idx, (DatetimeIndex, TimedeltaIndex, PeriodIndex)):
pytest.skip("Tested elsewhere.")

identity = mapper(idx.values, idx)
Expand Down
14 changes: 7 additions & 7 deletions pandas/tests/indexes/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def test_set_ops_error_cases(self, case, method, index):
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
def test_intersection_base(self, index):
if isinstance(index, CategoricalIndex):
return
pytest.skip(f"Not relevant for {type(index).__name__}")

first = index[:5]
second = index[:3]
Expand Down Expand Up @@ -280,13 +280,13 @@ def test_difference_base(self, sort, index):
)
def test_symmetric_difference(self, index):
if isinstance(index, CategoricalIndex):
return
pytest.skip(f"Not relevant for {type(index).__name__}")
if len(index) < 2:
return
pytest.skip("Too few values for test")
if index[0] in index[1:] or index[-1] in index[:-1]:
# index fixture has e.g. an index of bools that does not satisfy this,
# another with [0, 0, 1, 1, 2, 2]
return
pytest.skip("Index values no not satisfy test condition.")

first = index[1:]
second = index[:-1]
Expand Down Expand Up @@ -465,7 +465,7 @@ def test_difference_preserves_type_empty(self, index, sort):
# If taking difference of a set and itself, it
# needs to preserve the type of the index
if not index.is_unique:
return
pytest.skip("Not relevant since index is not unique")
result = index.difference(index, sort=sort)
expected = index[:0]
tm.assert_index_equal(result, expected, exact=True)
Expand All @@ -488,7 +488,7 @@ def test_intersection_difference_match_empty(self, index, sort):
# empty index produces the same index as the difference
# of an index with itself. Test for all types
if not index.is_unique:
return
pytest.skip("Not relevant because index is not unique")
inter = index.intersection(index[:0])
diff = index.difference(index, sort=sort)
tm.assert_index_equal(inter, diff, exact=True)
Expand Down Expand Up @@ -521,7 +521,7 @@ def test_intersection_duplicates_all_indexes(index):
# GH#38743
if index.empty:
# No duplicates in empty indexes
return
pytest.skip("Not relevant for empty Index")

idx = index
idx_non_unique = idx[[0, 0, 1, 2]]
Expand Down
Loading