Skip to content

Commit 8cead13

Browse files
authored
CLN: tests (#44148)
1 parent ee36b7a commit 8cead13

File tree

15 files changed

+84
-69
lines changed

15 files changed

+84
-69
lines changed

pandas/tests/frame/methods/test_cov_corr.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,14 @@ def test_corr_nullable_integer(self, nullable_column, other_column, method):
189189
expected = DataFrame(np.ones((2, 2)), columns=["a", "b"], index=["a", "b"])
190190
tm.assert_frame_equal(result, expected)
191191

192-
def test_corr_item_cache(self, using_array_manager):
192+
def test_corr_item_cache(self):
193193
# Check that corr does not lead to incorrect entries in item_cache
194194

195195
df = DataFrame({"A": range(10)})
196196
df["B"] = range(10)[::-1]
197197

198198
ser = df["A"] # populate item_cache
199-
if not using_array_manager:
200-
assert len(df._mgr.blocks) == 2
199+
assert len(df._mgr.arrays) == 2 # i.e. 2 blocks
201200

202201
_ = df.corr()
203202

pandas/tests/frame/test_repr_info.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@
2626

2727

2828
class TestDataFrameReprInfoEtc:
29-
def test_repr_bytes_61_lines(self, using_array_manager):
29+
def test_repr_bytes_61_lines(self):
3030
# GH#12857
3131
lets = list("ACDEFGHIJKLMNOP")
3232
slen = 50
3333
nseqs = 1000
3434
words = [[np.random.choice(lets) for x in range(slen)] for _ in range(nseqs)]
3535
df = DataFrame(words).astype("U1")
36-
# TODO(Arraymanager) astype("U1") actually gives this dtype instead of object
37-
if not using_array_manager:
38-
assert (df.dtypes == object).all()
36+
assert (df.dtypes == object).all()
3937

4038
# smoke tests; at one point this raised with 61 but not 60
4139
repr(df)

pandas/tests/groupby/test_allowlist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ def test_groupby_selection_tshift_raises(df):
406406
def test_groupby_selection_other_methods(df):
407407
# some methods which require DatetimeIndex
408408
rng = date_range("2014", periods=len(df))
409+
df.columns.name = "foo"
409410
df.index = rng
410411

411412
g = df.groupby(["A"])[["C"]]

pandas/tests/indexing/test_loc.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ def test_loc_setitem_missing_columns(self, index, box, expected):
838838

839839
def test_loc_coercion(self):
840840

841-
# 12411
841+
# GH#12411
842842
df = DataFrame({"date": [Timestamp("20130101").tz_localize("UTC"), pd.NaT]})
843843
expected = df.dtypes
844844

@@ -848,7 +848,8 @@ def test_loc_coercion(self):
848848
result = df.iloc[[1]]
849849
tm.assert_series_equal(result.dtypes, expected)
850850

851-
# 12045
851+
def test_loc_coercion2(self):
852+
# GH#12045
852853
import datetime
853854

854855
df = DataFrame(
@@ -862,7 +863,8 @@ def test_loc_coercion(self):
862863
result = df.iloc[[1]]
863864
tm.assert_series_equal(result.dtypes, expected)
864865

865-
# 11594
866+
def test_loc_coercion3(self):
867+
# GH#11594
866868
df = DataFrame({"text": ["some words"] + [None] * 9})
867869
expected = df.dtypes
868870

pandas/tests/indexing/test_partial.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def test_partial_setting(self):
122122
df.loc[:, "C"] = df.loc[:, "A"]
123123
tm.assert_frame_equal(df, expected)
124124

125+
def test_partial_setting2(self):
125126
# GH 8473
126127
dates = date_range("1/1/2000", periods=8)
127128
df_orig = DataFrame(

pandas/tests/resample/test_datetime_index.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,14 @@ def test_resample_ohlc_dataframe():
575575
}
576576
)
577577
).reindex(["VOLUME", "PRICE"], axis=1)
578+
df.columns.name = "Cols"
578579
res = df.resample("H").ohlc()
579580
exp = pd.concat(
580581
[df["VOLUME"].resample("H").ohlc(), df["PRICE"].resample("H").ohlc()],
581582
axis=1,
582-
keys=["VOLUME", "PRICE"],
583+
keys=df.columns,
583584
)
585+
assert exp.columns.names[0] == "Cols"
584586
tm.assert_frame_equal(exp, res)
585587

586588
df.columns = [["a", "b"], ["c", "d"]]

pandas/tests/scalar/period/test_period.py

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,28 +1312,29 @@ def test_add_offset(self):
13121312
assert p + offsets.MonthEnd(12) == exp
13131313
assert offsets.MonthEnd(12) + p == exp
13141314

1315+
msg = "|".join(
1316+
[
1317+
"Input has different freq",
1318+
"Input cannot be converted to Period",
1319+
]
1320+
)
1321+
13151322
for o in [
13161323
offsets.YearBegin(2),
13171324
offsets.MonthBegin(1),
13181325
offsets.Minute(),
13191326
np.timedelta64(365, "D"),
13201327
timedelta(365),
13211328
]:
1322-
msg = "Input has different freq|Input cannot be converted to Period"
1329+
13231330
with pytest.raises(IncompatibleFrequency, match=msg):
13241331
p + o
13251332

13261333
if isinstance(o, np.timedelta64):
1327-
msg = "cannot use operands with types"
1328-
with pytest.raises(TypeError, match=msg):
1334+
td_msg = "cannot use operands with types"
1335+
with pytest.raises(TypeError, match=td_msg):
13291336
o + p
13301337
else:
1331-
msg = "|".join(
1332-
[
1333-
"Input has different freq",
1334-
"Input cannot be converted to Period",
1335-
]
1336-
)
13371338
with pytest.raises(IncompatibleFrequency, match=msg):
13381339
o + p
13391340

@@ -1368,28 +1369,28 @@ def test_add_offset(self):
13681369
assert p + timedelta(hours=48) == exp
13691370
assert timedelta(hours=48) + p == exp
13701371

1372+
msg = "|".join(
1373+
[
1374+
"Input has different freq",
1375+
"Input cannot be converted to Period",
1376+
]
1377+
)
1378+
13711379
for o in [
13721380
offsets.YearBegin(2),
13731381
offsets.MonthBegin(1),
13741382
offsets.Minute(),
13751383
np.timedelta64(4, "h"),
13761384
timedelta(hours=23),
13771385
]:
1378-
msg = "Input has different freq|Input cannot be converted to Period"
13791386
with pytest.raises(IncompatibleFrequency, match=msg):
13801387
p + o
13811388

13821389
if isinstance(o, np.timedelta64):
1383-
msg = "cannot use operands with types"
1384-
with pytest.raises(TypeError, match=msg):
1390+
td_msg = "cannot use operands with types"
1391+
with pytest.raises(TypeError, match=td_msg):
13851392
o + p
13861393
else:
1387-
msg = "|".join(
1388-
[
1389-
"Input has different freq",
1390-
"Input cannot be converted to Period",
1391-
]
1392-
)
13931394
with pytest.raises(IncompatibleFrequency, match=msg):
13941395
o + p
13951396

@@ -1423,34 +1424,40 @@ def test_add_offset(self):
14231424
assert p + timedelta(days=4, minutes=180) == exp
14241425
assert timedelta(days=4, minutes=180) + p == exp
14251426

1427+
msg = "|".join(
1428+
[
1429+
"Input has different freq",
1430+
"Input cannot be converted to Period",
1431+
]
1432+
)
1433+
14261434
for o in [
14271435
offsets.YearBegin(2),
14281436
offsets.MonthBegin(1),
14291437
offsets.Minute(),
14301438
np.timedelta64(3200, "s"),
14311439
timedelta(hours=23, minutes=30),
14321440
]:
1433-
msg = "Input has different freq|Input cannot be converted to Period"
14341441
with pytest.raises(IncompatibleFrequency, match=msg):
14351442
p + o
14361443

14371444
if isinstance(o, np.timedelta64):
1438-
msg = "cannot use operands with types"
1439-
with pytest.raises(TypeError, match=msg):
1445+
td_msg = "cannot use operands with types"
1446+
with pytest.raises(TypeError, match=td_msg):
14401447
o + p
14411448
else:
1442-
msg = "|".join(
1443-
[
1444-
"Input has different freq",
1445-
"Input cannot be converted to Period",
1446-
]
1447-
)
14481449
with pytest.raises(IncompatibleFrequency, match=msg):
14491450
o + p
14501451

14511452
def test_sub_offset(self):
14521453
# freq is DateOffset
1453-
msg = "Input has different freq|Input cannot be converted to Period"
1454+
msg = "|".join(
1455+
[
1456+
"Input has different freq",
1457+
"Input cannot be converted to Period",
1458+
]
1459+
)
1460+
14541461
for freq in ["A", "2A", "3A"]:
14551462
p = Period("2011", freq=freq)
14561463
assert p - offsets.YearEnd(2) == Period("2009", freq=freq)

pandas/tests/scalar/timedelta/test_arithmetic.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,14 @@ def test_ops_ndarray(self):
273273
msg = r"unsupported operand type\(s\) for \+: 'Timedelta' and 'int'"
274274
with pytest.raises(TypeError, match=msg):
275275
td + np.array([1])
276-
msg = (
277-
r"unsupported operand type\(s\) for \+: 'numpy.ndarray' and 'Timedelta'|"
278-
"Concatenation operation is not implemented for NumPy arrays"
276+
msg = "|".join(
277+
[
278+
(
279+
r"unsupported operand type\(s\) for \+: 'numpy.ndarray' "
280+
"and 'Timedelta'"
281+
),
282+
"Concatenation operation is not implemented for NumPy arrays",
283+
]
279284
)
280285
with pytest.raises(TypeError, match=msg):
281286
np.array([1]) + td

pandas/tests/series/indexing/test_getitem.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,12 @@ def test_getitem_partial_str_slice_high_reso_with_timedeltaindex(self):
234234
result = ser["1 days, 10:11:12.001001"]
235235
assert result == ser.iloc[1001]
236236

237-
def test_getitem_slice_2d(self, datetime_series, using_array_manager):
237+
# TODO: redundant with test_getitem_ndim_deprecated?
238+
def test_getitem_slice_2d(self, datetime_series):
238239
# GH#30588 multi-dimensional indexing deprecated
239240

240241
with tm.assert_produces_warning(
241-
FutureWarning, check_stacklevel=not using_array_manager
242+
FutureWarning, match="Support for multi-dimensional indexing"
242243
):
243244
# GH#30867 Don't want to support this long-term, but
244245
# for now ensure that the warning from Index
@@ -520,11 +521,10 @@ def test_getitem_generator(string_series):
520521
Series(date_range("2012-01-01", periods=2, tz="CET")),
521522
],
522523
)
523-
def test_getitem_ndim_deprecated(series, using_array_manager):
524+
def test_getitem_ndim_deprecated(series):
524525
with tm.assert_produces_warning(
525526
FutureWarning,
526527
match="Support for multi-dimensional indexing",
527-
check_stacklevel=not using_array_manager,
528528
):
529529
result = series[:, None]
530530

pandas/tests/series/methods/test_fillna.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,12 @@ def test_fillna_method_and_limit_invalid(self):
742742

743743
# related GH#9217, make sure limit is an int and greater than 0
744744
ser = Series([1, 2, 3, None])
745-
msg = (
746-
r"Cannot specify both 'value' and 'method'\.|"
747-
r"Limit must be greater than 0|"
748-
"Limit must be an integer"
745+
msg = "|".join(
746+
[
747+
r"Cannot specify both 'value' and 'method'\.",
748+
"Limit must be greater than 0",
749+
"Limit must be an integer",
750+
]
749751
)
750752
for limit in [-1, 0, 1.0, 2.0]:
751753
for method in ["backfill", "bfill", "pad", "ffill", None]:

pandas/tests/test_algos.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,7 @@ def test_complex_sorting(self):
241241
# gh 12666 - check no segfault
242242
x17 = np.array([complex(i) for i in range(17)], dtype=object)
243243

244-
msg = (
245-
"unorderable types: .* [<>] .*"
246-
"|" # the above case happens for numpy < 1.14
247-
"'[<>]' not supported between instances of .*"
248-
)
244+
msg = "'[<>]' not supported between instances of .*"
249245
with pytest.raises(TypeError, match=msg):
250246
algos.factorize(x17[::-1], sort=True)
251247

pandas/tests/test_sorting.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,7 @@ def test_mixed_integer_from_list(self):
434434
def test_unsortable(self):
435435
# GH 13714
436436
arr = np.array([1, 2, datetime.now(), 0, 3], dtype=object)
437-
msg = (
438-
"unorderable types: .* [<>] .*"
439-
"|" # the above case happens for numpy < 1.14
440-
"'[<>]' not supported between instances of .*"
441-
)
437+
msg = "'[<>]' not supported between instances of .*"
442438
with pytest.raises(TypeError, match=msg):
443439
safe_sort(arr)
444440

pandas/tests/test_take.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,11 @@ def test_take_empty(self, allow_fill):
313313
result = algos.take(arr, [], allow_fill=allow_fill)
314314
tm.assert_numpy_array_equal(arr, result)
315315

316-
msg = (
317-
"cannot do a non-empty take from an empty axes.|"
318-
"indices are out-of-bounds"
316+
msg = "|".join(
317+
[
318+
"cannot do a non-empty take from an empty axes.",
319+
"indices are out-of-bounds",
320+
]
319321
)
320322
with pytest.raises(IndexError, match=msg):
321323
algos.take(arr, [0], allow_fill=allow_fill)

pandas/tests/tseries/frequencies/test_inference.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,11 @@ def test_non_datetime_index2():
399399
"idx", [tm.makeIntIndex(10), tm.makeFloatIndex(10), tm.makePeriodIndex(10)]
400400
)
401401
def test_invalid_index_types(idx):
402-
msg = (
403-
"(cannot infer freq from a non-convertible)|"
404-
"(Check the `freq` attribute instead of using infer_freq)"
402+
msg = "|".join(
403+
[
404+
"cannot infer freq from a non-convertible",
405+
"Check the `freq` attribute instead of using infer_freq",
406+
]
405407
)
406408

407409
with pytest.raises(TypeError, match=msg):

pandas/tests/window/test_rolling.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ def test_invalid_constructor(frame_or_series, w):
6363

6464
c = frame_or_series(range(5)).rolling
6565

66-
msg = (
67-
"window must be an integer|"
68-
"passed window foo is not compatible with a datetimelike index"
66+
msg = "|".join(
67+
[
68+
"window must be an integer",
69+
"passed window foo is not compatible with a datetimelike index",
70+
]
6971
)
7072
with pytest.raises(ValueError, match=msg):
7173
c(window=w)

0 commit comments

Comments
 (0)