Skip to content

CLN: tests #44148

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 2 commits into from
Oct 24, 2021
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
5 changes: 2 additions & 3 deletions pandas/tests/frame/methods/test_cov_corr.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,14 @@ def test_corr_nullable_integer(self, nullable_column, other_column, method):
expected = DataFrame(np.ones((2, 2)), columns=["a", "b"], index=["a", "b"])
tm.assert_frame_equal(result, expected)

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

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

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

_ = df.corr()

Expand Down
6 changes: 2 additions & 4 deletions pandas/tests/frame/test_repr_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@


class TestDataFrameReprInfoEtc:
def test_repr_bytes_61_lines(self, using_array_manager):
def test_repr_bytes_61_lines(self):
# GH#12857
lets = list("ACDEFGHIJKLMNOP")
slen = 50
nseqs = 1000
words = [[np.random.choice(lets) for x in range(slen)] for _ in range(nseqs)]
df = DataFrame(words).astype("U1")
# TODO(Arraymanager) astype("U1") actually gives this dtype instead of object
if not using_array_manager:
assert (df.dtypes == object).all()
assert (df.dtypes == object).all()

# smoke tests; at one point this raised with 61 but not 60
repr(df)
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/groupby/test_allowlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ def test_groupby_selection_tshift_raises(df):
def test_groupby_selection_other_methods(df):
# some methods which require DatetimeIndex
rng = date_range("2014", periods=len(df))
df.columns.name = "foo"
df.index = rng

g = df.groupby(["A"])[["C"]]
Expand Down
8 changes: 5 additions & 3 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ def test_loc_setitem_missing_columns(self, index, box, expected):

def test_loc_coercion(self):

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

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

# 12045
def test_loc_coercion2(self):
# GH#12045
import datetime

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

# 11594
def test_loc_coercion3(self):
# GH#11594
df = DataFrame({"text": ["some words"] + [None] * 9})
expected = df.dtypes

Expand Down
1 change: 1 addition & 0 deletions pandas/tests/indexing/test_partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def test_partial_setting(self):
df.loc[:, "C"] = df.loc[:, "A"]
tm.assert_frame_equal(df, expected)

def test_partial_setting2(self):
# GH 8473
dates = date_range("1/1/2000", periods=8)
df_orig = DataFrame(
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/resample/test_datetime_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,14 @@ def test_resample_ohlc_dataframe():
}
)
).reindex(["VOLUME", "PRICE"], axis=1)
df.columns.name = "Cols"
res = df.resample("H").ohlc()
exp = pd.concat(
[df["VOLUME"].resample("H").ohlc(), df["PRICE"].resample("H").ohlc()],
axis=1,
keys=["VOLUME", "PRICE"],
keys=df.columns,
)
assert exp.columns.names[0] == "Cols"
tm.assert_frame_equal(exp, res)

df.columns = [["a", "b"], ["c", "d"]]
Expand Down
63 changes: 35 additions & 28 deletions pandas/tests/scalar/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,28 +1312,29 @@ def test_add_offset(self):
assert p + offsets.MonthEnd(12) == exp
assert offsets.MonthEnd(12) + p == exp

msg = "|".join(
[
"Input has different freq",
"Input cannot be converted to Period",
]
)

for o in [
offsets.YearBegin(2),
offsets.MonthBegin(1),
offsets.Minute(),
np.timedelta64(365, "D"),
timedelta(365),
]:
msg = "Input has different freq|Input cannot be converted to Period"

with pytest.raises(IncompatibleFrequency, match=msg):
p + o

if isinstance(o, np.timedelta64):
msg = "cannot use operands with types"
with pytest.raises(TypeError, match=msg):
td_msg = "cannot use operands with types"
with pytest.raises(TypeError, match=td_msg):
o + p
else:
msg = "|".join(
[
"Input has different freq",
"Input cannot be converted to Period",
]
)
with pytest.raises(IncompatibleFrequency, match=msg):
o + p

Expand Down Expand Up @@ -1368,28 +1369,28 @@ def test_add_offset(self):
assert p + timedelta(hours=48) == exp
assert timedelta(hours=48) + p == exp

msg = "|".join(
[
"Input has different freq",
"Input cannot be converted to Period",
]
)

for o in [
offsets.YearBegin(2),
offsets.MonthBegin(1),
offsets.Minute(),
np.timedelta64(4, "h"),
timedelta(hours=23),
]:
msg = "Input has different freq|Input cannot be converted to Period"
with pytest.raises(IncompatibleFrequency, match=msg):
p + o

if isinstance(o, np.timedelta64):
msg = "cannot use operands with types"
with pytest.raises(TypeError, match=msg):
td_msg = "cannot use operands with types"
with pytest.raises(TypeError, match=td_msg):
o + p
else:
msg = "|".join(
[
"Input has different freq",
"Input cannot be converted to Period",
]
)
with pytest.raises(IncompatibleFrequency, match=msg):
o + p

Expand Down Expand Up @@ -1423,34 +1424,40 @@ def test_add_offset(self):
assert p + timedelta(days=4, minutes=180) == exp
assert timedelta(days=4, minutes=180) + p == exp

msg = "|".join(
[
"Input has different freq",
"Input cannot be converted to Period",
]
)

for o in [
offsets.YearBegin(2),
offsets.MonthBegin(1),
offsets.Minute(),
np.timedelta64(3200, "s"),
timedelta(hours=23, minutes=30),
]:
msg = "Input has different freq|Input cannot be converted to Period"
with pytest.raises(IncompatibleFrequency, match=msg):
p + o

if isinstance(o, np.timedelta64):
msg = "cannot use operands with types"
with pytest.raises(TypeError, match=msg):
td_msg = "cannot use operands with types"
with pytest.raises(TypeError, match=td_msg):
o + p
else:
msg = "|".join(
[
"Input has different freq",
"Input cannot be converted to Period",
]
)
with pytest.raises(IncompatibleFrequency, match=msg):
o + p

def test_sub_offset(self):
# freq is DateOffset
msg = "Input has different freq|Input cannot be converted to Period"
msg = "|".join(
[
"Input has different freq",
"Input cannot be converted to Period",
]
)

for freq in ["A", "2A", "3A"]:
p = Period("2011", freq=freq)
assert p - offsets.YearEnd(2) == Period("2009", freq=freq)
Expand Down
11 changes: 8 additions & 3 deletions pandas/tests/scalar/timedelta/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,14 @@ def test_ops_ndarray(self):
msg = r"unsupported operand type\(s\) for \+: 'Timedelta' and 'int'"
with pytest.raises(TypeError, match=msg):
td + np.array([1])
msg = (
r"unsupported operand type\(s\) for \+: 'numpy.ndarray' and 'Timedelta'|"
"Concatenation operation is not implemented for NumPy arrays"
msg = "|".join(
[
(
r"unsupported operand type\(s\) for \+: 'numpy.ndarray' "
"and 'Timedelta'"
),
"Concatenation operation is not implemented for NumPy arrays",
]
)
with pytest.raises(TypeError, match=msg):
np.array([1]) + td
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/series/indexing/test_getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,12 @@ def test_getitem_partial_str_slice_high_reso_with_timedeltaindex(self):
result = ser["1 days, 10:11:12.001001"]
assert result == ser.iloc[1001]

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

with tm.assert_produces_warning(
FutureWarning, check_stacklevel=not using_array_manager
FutureWarning, match="Support for multi-dimensional indexing"
):
# GH#30867 Don't want to support this long-term, but
# for now ensure that the warning from Index
Expand Down Expand Up @@ -520,11 +521,10 @@ def test_getitem_generator(string_series):
Series(date_range("2012-01-01", periods=2, tz="CET")),
],
)
def test_getitem_ndim_deprecated(series, using_array_manager):
def test_getitem_ndim_deprecated(series):
with tm.assert_produces_warning(
FutureWarning,
match="Support for multi-dimensional indexing",
check_stacklevel=not using_array_manager,
):
result = series[:, None]

Expand Down
10 changes: 6 additions & 4 deletions pandas/tests/series/methods/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,12 @@ def test_fillna_method_and_limit_invalid(self):

# related GH#9217, make sure limit is an int and greater than 0
ser = Series([1, 2, 3, None])
msg = (
r"Cannot specify both 'value' and 'method'\.|"
r"Limit must be greater than 0|"
"Limit must be an integer"
msg = "|".join(
[
r"Cannot specify both 'value' and 'method'\.",
"Limit must be greater than 0",
"Limit must be an integer",
]
)
for limit in [-1, 0, 1.0, 2.0]:
for method in ["backfill", "bfill", "pad", "ffill", None]:
Expand Down
6 changes: 1 addition & 5 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,7 @@ def test_complex_sorting(self):
# gh 12666 - check no segfault
x17 = np.array([complex(i) for i in range(17)], dtype=object)

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

Expand Down
6 changes: 1 addition & 5 deletions pandas/tests/test_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,7 @@ def test_mixed_integer_from_list(self):
def test_unsortable(self):
# GH 13714
arr = np.array([1, 2, datetime.now(), 0, 3], dtype=object)
msg = (
"unorderable types: .* [<>] .*"
"|" # the above case happens for numpy < 1.14
"'[<>]' not supported between instances of .*"
)
msg = "'[<>]' not supported between instances of .*"
with pytest.raises(TypeError, match=msg):
safe_sort(arr)

Expand Down
8 changes: 5 additions & 3 deletions pandas/tests/test_take.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,11 @@ def test_take_empty(self, allow_fill):
result = algos.take(arr, [], allow_fill=allow_fill)
tm.assert_numpy_array_equal(arr, result)

msg = (
"cannot do a non-empty take from an empty axes.|"
"indices are out-of-bounds"
msg = "|".join(
[
"cannot do a non-empty take from an empty axes.",
"indices are out-of-bounds",
]
)
with pytest.raises(IndexError, match=msg):
algos.take(arr, [0], allow_fill=allow_fill)
Expand Down
8 changes: 5 additions & 3 deletions pandas/tests/tseries/frequencies/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,11 @@ def test_non_datetime_index2():
"idx", [tm.makeIntIndex(10), tm.makeFloatIndex(10), tm.makePeriodIndex(10)]
)
def test_invalid_index_types(idx):
msg = (
"(cannot infer freq from a non-convertible)|"
"(Check the `freq` attribute instead of using infer_freq)"
msg = "|".join(
[
"cannot infer freq from a non-convertible",
"Check the `freq` attribute instead of using infer_freq",
]
)

with pytest.raises(TypeError, match=msg):
Expand Down
8 changes: 5 additions & 3 deletions pandas/tests/window/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ def test_invalid_constructor(frame_or_series, w):

c = frame_or_series(range(5)).rolling

msg = (
"window must be an integer|"
"passed window foo is not compatible with a datetimelike index"
msg = "|".join(
[
"window must be an integer",
"passed window foo is not compatible with a datetimelike index",
]
)
with pytest.raises(ValueError, match=msg):
c(window=w)
Expand Down