Skip to content

Commit 83c26ac

Browse files
committed
TST: More explicit test patterns (pandas-dev#54463)
1 parent 7434a8b commit 83c26ac

32 files changed

+120
-135
lines changed

pandas/tests/arithmetic/test_datetime64.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,7 @@ def test_dti_cmp_datetimelike(self, other, tz_naive_fixture):
414414
dti = date_range("2016-01-01", periods=2, tz=tz)
415415
if tz is not None:
416416
if isinstance(other, np.datetime64):
417-
# no tzaware version available
418-
return
417+
pytest.skip("no tzaware version available")
419418
other = localize_pydatetime(other, dti.tzinfo)
420419

421420
result = dti == other
@@ -1080,13 +1079,14 @@ def test_dt64arr_add_dtlike_raises(self, tz_naive_fixture, box_with_array):
10801079
@pytest.mark.parametrize("freq", ["H", "D", "W", "M", "MS", "Q", "B", None])
10811080
@pytest.mark.parametrize("dtype", [None, "uint8"])
10821081
def test_dt64arr_addsub_intlike(
1083-
self, dtype, box_with_array, freq, tz_naive_fixture
1082+
self, request, dtype, box_with_array, freq, tz_naive_fixture
10841083
):
10851084
# GH#19959, GH#19123, GH#19012
10861085
tz = tz_naive_fixture
10871086
if box_with_array is pd.DataFrame:
1088-
# alignment headaches
1089-
return
1087+
request.node.add_marker(
1088+
pytest.mark.xfail(raises=ValueError, reason="Axis alignment fails")
1089+
)
10901090

10911091
if freq is None:
10921092
dti = DatetimeIndex(["NaT", "2017-04-05 06:07:08"], tz=tz)

pandas/tests/arithmetic/test_numeric.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def test_divmod_zero(self, zero, numeric_idx):
377377
def test_div_negative_zero(self, zero, numeric_idx, op):
378378
# Check that -1 / -0.0 returns np.inf, not -np.inf
379379
if numeric_idx.dtype == np.uint64:
380-
return
380+
pytest.skip(f"Not relevant for {numeric_idx.dtype}")
381381
idx = numeric_idx - 3
382382

383383
expected = Index([-np.inf, -np.inf, -np.inf, np.nan, np.inf], dtype=np.float64)

pandas/tests/arithmetic/test_timedelta64.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ def test_td64arr_add_sub_datetimelike_scalar(
10021002
ts = dt_scalar.to_pydatetime()
10031003
elif cls is np.datetime64:
10041004
if tz_naive_fixture is not None:
1005-
return
1005+
pytest.skip(f"{cls} doesn support {tz_naive_fixture}")
10061006
ts = dt_scalar.to_datetime64()
10071007
else:
10081008
ts = dt_scalar

pandas/tests/frame/methods/test_to_csv.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,7 @@ def create_cols(name):
674674

675675
# add in some nans
676676
df_float.iloc[30:50, 1:3] = np.nan
677-
678-
# ## this is a bug in read_csv right now ####
679-
# df_dt.loc[30:50,1:3] = np.nan
680-
# FIXME: don't leave commented-out
677+
df_dt.iloc[30:50, 1:3] = np.nan
681678

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

pandas/tests/frame/test_arithmetic.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,12 @@ def test_inplace_ops_identity(self):
17661766
[
17671767
"add",
17681768
"and",
1769-
"div",
1769+
pytest.param(
1770+
"div",
1771+
marks=pytest.mark.xfail(
1772+
raises=AttributeError, reason="__idiv__ not implemented"
1773+
),
1774+
),
17701775
"floordiv",
17711776
"mod",
17721777
"mul",
@@ -1778,9 +1783,6 @@ def test_inplace_ops_identity(self):
17781783
],
17791784
)
17801785
def test_inplace_ops_identity2(self, op):
1781-
if op == "div":
1782-
return
1783-
17841786
df = DataFrame({"a": [1.0, 2.0, 3.0], "b": [1, 2, 3]})
17851787

17861788
operand = 2

pandas/tests/frame/test_constructors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,7 @@ def test_dict_nocopy(
25142514
b = np.array([3, 4], dtype=any_numpy_dtype)
25152515
if b.dtype.kind in ["S", "U"]:
25162516
# These get cast, making the checks below more cumbersome
2517-
return
2517+
pytest.skip(f"{b.dtype} get cast, making the checks below more cumbersome")
25182518

25192519
c = pd.array([1, 2], dtype=any_numeric_ea_dtype)
25202520
c_orig = c.copy()

pandas/tests/groupby/test_api.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ def test_frame_consistency(groupby_func):
205205
def test_series_consistency(request, groupby_func):
206206
# GH#48028
207207
if groupby_func in ("first", "last"):
208-
# first and last are entirely different between Series and groupby
209-
return
208+
pytest.skip("first and last are entirely different between Series and groupby")
210209

211210
if groupby_func in ("cumcount", "corrwith", "ngroup"):
212211
assert not hasattr(Series, groupby_func)

pandas/tests/groupby/transform/test_transform.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,8 @@ def frame_mi(frame):
775775
{"by": np.random.default_rng(2).integers(0, 50, size=10).astype(float)},
776776
{"level": 0},
777777
{"by": "string"},
778-
# {"by": 'string_missing'}]:
779-
# {"by": ['int','string']}]:
780-
# TODO: remove or enable commented-out code
778+
pytest.param({"by": "string_missing"}, marks=pytest.mark.xfail),
779+
{"by": ["int", "string"]},
781780
],
782781
)
783782
def test_cython_transform_frame(request, op, args, targop, df_fix, gb_target):
@@ -825,9 +824,9 @@ def test_cython_transform_frame(request, op, args, targop, df_fix, gb_target):
825824
{"by": np.random.default_rng(2).integers(0, 50, size=10).astype(float)},
826825
{"level": 0},
827826
{"by": "string"},
828-
# {"by": 'string_missing'}]:
829-
# {"by": ['int','string']}]:
830-
# TODO: remove or enable commented-out code
827+
# TODO: create xfail condition given other params
828+
# {"by": 'string_missing'},
829+
{"by": ["int", "string"]},
831830
],
832831
)
833832
@pytest.mark.parametrize(

pandas/tests/indexes/multi/test_setops.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,7 @@ def test_union_with_duplicates_keep_ea_dtype(dupe_val, any_numeric_ea_dtype):
626626
def test_union_duplicates(index, request):
627627
# GH#38977
628628
if index.empty or isinstance(index, (IntervalIndex, CategoricalIndex)):
629-
# No duplicates in empty indexes
630-
return
629+
pytest.skip(f"No duplicates in an empty {type(index).__name__}")
631630

632631
values = index.unique().values.tolist()
633632
mi1 = MultiIndex.from_arrays([values, [1] * len(values)])

pandas/tests/indexes/test_any_index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_hash_error(index):
3434

3535
def test_mutability(index):
3636
if not len(index):
37-
return
37+
pytest.skip("Test doesn't make sense for empty index")
3838
msg = "Index does not support mutable operations"
3939
with pytest.raises(TypeError, match=msg):
4040
index[0] = index[0]

pandas/tests/indexes/test_base.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,9 @@ def test_map_dictlike_simple(self, mapper):
561561
def test_map_dictlike(self, index, mapper, request):
562562
# GH 12756
563563
if isinstance(index, CategoricalIndex):
564-
# Tested in test_categorical
565-
return
564+
pytest.skip("Tested in test_categorical")
566565
elif not index.is_unique:
567-
# Cannot map duplicated index
568-
return
566+
pytest.skip("Cannot map duplicated index")
569567

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

@@ -785,7 +783,7 @@ def test_drop_tuple(self, values, to_drop):
785783
def test_drop_with_duplicates_in_index(self, index):
786784
# GH38051
787785
if len(index) == 0 or isinstance(index, MultiIndex):
788-
return
786+
pytest.skip("Test doesn't make sense for empty MultiIndex")
789787
if isinstance(index, IntervalIndex) and not IS64:
790788
pytest.skip("Cannot test IntervalIndex with int64 dtype on 32 bit platform")
791789
index = index.unique().repeat(2)

pandas/tests/indexes/test_common.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,6 @@ def test_set_name_methods(self, index_flat):
121121
assert res is None
122122
assert index.name == new_name
123123
assert index.names == (new_name,)
124-
# FIXME: dont leave commented-out
125-
# with pytest.raises(TypeError, match="list-like"):
126-
# # should still fail even if it would be the right length
127-
# ind.set_names("a")
128124
with pytest.raises(ValueError, match="Level must be None"):
129125
index.set_names("a", level=0)
130126

@@ -134,6 +130,12 @@ def test_set_name_methods(self, index_flat):
134130
assert index.name == name
135131
assert index.names == (name,)
136132

133+
@pytest.mark.xfail
134+
def test_set_names_single_label_no_level(self, index_flat):
135+
with pytest.raises(TypeError, match="list-like"):
136+
# should still fail even if it would be the right length
137+
index_flat.set_names("a")
138+
137139
def test_copy_and_deepcopy(self, index_flat):
138140
index = index_flat
139141

pandas/tests/indexes/test_index_new.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ def test_constructor_infer_nat_dt_like(
132132
):
133133
if isinstance(nulls_fixture, Decimal):
134134
# We dont cast these to datetime64/timedelta64
135-
return
135+
pytest.skip(
136+
f"We don't cast {type(nulls_fixture).__name__} to "
137+
"datetime64/timedelta64"
138+
)
136139

137140
expected = klass([NaT, NaT])
138141
assert expected.dtype == dtype

pandas/tests/indexes/test_indexing.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def test_take_invalid_kwargs(self, index):
5656
def test_take(self, index):
5757
indexer = [4, 3, 0, 2]
5858
if len(index) < 5:
59-
# not enough elements; ignore
60-
return
59+
pytest.skip("Test doesn't make sense since not enough elements")
6160

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

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

@@ -289,7 +288,7 @@ class TestPutmask:
289288
def test_putmask_with_wrong_mask(self, index):
290289
# GH#18368
291290
if not len(index):
292-
return
291+
pytest.skip("Test doesn't make sense for empty index")
293292

294293
fill = index[0]
295294

pandas/tests/indexes/test_numpy_compat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def test_numpy_ufuncs_other(index, func):
154154
def test_numpy_ufuncs_reductions(index, func, request):
155155
# TODO: overlap with tests.series.test_ufunc.test_reductions
156156
if len(index) == 0:
157-
return
157+
pytest.skip("Test doesn't make sense for empty index.")
158158

159159
if isinstance(index, CategoricalIndex) and index.dtype.ordered is False:
160160
with pytest.raises(TypeError, match="is not ordered for"):

pandas/tests/indexes/test_old_base.py

+15-24
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def test_numeric_compat(self, simple_index):
167167
# we can remove multi.test_compat.test_numeric_compat
168168
assert not isinstance(idx, MultiIndex)
169169
if type(idx) is Index:
170-
return
170+
pytest.skip("Not applicable for Index")
171171
if is_numeric_dtype(simple_index.dtype) or isinstance(
172172
simple_index, TimedeltaIndex
173173
):
@@ -246,9 +246,10 @@ def test_ensure_copied_data(self, index):
246246
# Needs "freq" specification:
247247
init_kwargs["freq"] = index.freq
248248
elif isinstance(index, (RangeIndex, MultiIndex, CategoricalIndex)):
249-
# RangeIndex cannot be initialized from data
250-
# MultiIndex and CategoricalIndex are tested separately
251-
return
249+
pytest.skip(
250+
"RangeIndex cannot be initialized from data, "
251+
"MultiIndex and CategoricalIndex are tested separately"
252+
)
252253
elif index.dtype == object and index.inferred_type == "boolean":
253254
init_kwargs["dtype"] = index.dtype
254255

@@ -319,9 +320,8 @@ def test_memory_usage(self, index):
319320
assert result3 > result2
320321

321322
def test_argsort(self, index):
322-
# separately tested
323323
if isinstance(index, CategoricalIndex):
324-
return
324+
pytest.skip(f"{type(self).__name__} separately tested")
325325

326326
result = index.argsort()
327327
expected = np.array(index).argsort()
@@ -400,7 +400,7 @@ def test_insert_base(self, index):
400400
result = index[1:4]
401401

402402
if not len(index):
403-
return
403+
pytest.skip("Not applicable for empty index")
404404

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

435435
def test_delete_base(self, index):
436436
if not len(index):
437-
return
437+
pytest.skip("Not applicable for empty index")
438438

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

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

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

@@ -566,12 +564,11 @@ def test_format_empty(self, simple_index):
566564
def test_fillna(self, index):
567565
# GH 11343
568566
if len(index) == 0:
569-
return
567+
pytest.skip("Not relevant for empty index")
570568
elif index.dtype == bool:
571-
# can't hold NAs
572-
return
569+
pytest.skip(f"{index.dtype} cannot hold NAs")
573570
elif isinstance(index, Index) and is_integer_dtype(index.dtype):
574-
return
571+
pytest.skip(f"Not relevant for Index with {index.dtype}")
575572
elif isinstance(index, MultiIndex):
576573
idx = index.copy(deep=True)
577574
msg = "isna is not defined for MultiIndex"
@@ -654,15 +651,9 @@ def test_map(self, simple_index):
654651
],
655652
)
656653
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
657-
def test_map_dictlike(self, mapper, simple_index):
654+
def test_map_dictlike(self, mapper, simple_index, request):
658655
idx = simple_index
659-
if isinstance(idx, CategoricalIndex):
660-
# FIXME: this fails with CategoricalIndex bc it goes through
661-
# Categorical.map which ends up calling get_indexer with
662-
# non-unique values, which raises. This _should_ work fine for
663-
# CategoricalIndex.
664-
pytest.skip(f"skipping tests for {type(idx)}")
665-
elif isinstance(idx, (DatetimeIndex, TimedeltaIndex, PeriodIndex)):
656+
if isinstance(idx, (DatetimeIndex, TimedeltaIndex, PeriodIndex)):
666657
pytest.skip("Tested elsewhere.")
667658

668659
identity = mapper(idx.values, idx)

pandas/tests/indexes/test_setops.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def test_set_ops_error_cases(self, case, method, index):
194194
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
195195
def test_intersection_base(self, index):
196196
if isinstance(index, CategoricalIndex):
197-
return
197+
pytest.skip(f"Not relevant for {type(index).__name__}")
198198

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

291291
first = index[1:]
292292
second = index[:-1]
@@ -465,7 +465,7 @@ def test_difference_preserves_type_empty(self, index, sort):
465465
# If taking difference of a set and itself, it
466466
# needs to preserve the type of the index
467467
if not index.is_unique:
468-
return
468+
pytest.skip("Not relevant since index is not unique")
469469
result = index.difference(index, sort=sort)
470470
expected = index[:0]
471471
tm.assert_index_equal(result, expected, exact=True)
@@ -488,7 +488,7 @@ def test_intersection_difference_match_empty(self, index, sort):
488488
# empty index produces the same index as the difference
489489
# of an index with itself. Test for all types
490490
if not index.is_unique:
491-
return
491+
pytest.skip("Not relevant because index is not unique")
492492
inter = index.intersection(index[:0])
493493
diff = index.difference(index, sort=sort)
494494
tm.assert_index_equal(inter, diff, exact=True)
@@ -521,7 +521,7 @@ def test_intersection_duplicates_all_indexes(index):
521521
# GH#38743
522522
if index.empty:
523523
# No duplicates in empty indexes
524-
return
524+
pytest.skip("Not relevant for empty Index")
525525

526526
idx = index
527527
idx_non_unique = idx[[0, 0, 1, 2]]

0 commit comments

Comments
 (0)