From 41370ca2126aadf16e3926793a7272b517fe6a79 Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 22 Oct 2021 09:47:11 -0700 Subject: [PATCH] CLN: tests --- pandas/tests/frame/methods/test_cov_corr.py | 5 +- pandas/tests/frame/test_repr_info.py | 6 +- pandas/tests/groupby/test_allowlist.py | 1 + pandas/tests/indexing/test_loc.py | 8 ++- pandas/tests/indexing/test_partial.py | 1 + pandas/tests/resample/test_datetime_index.py | 4 +- pandas/tests/scalar/period/test_period.py | 63 ++++++++++--------- .../tests/scalar/timedelta/test_arithmetic.py | 11 +++- pandas/tests/series/indexing/test_getitem.py | 8 +-- pandas/tests/series/methods/test_fillna.py | 10 +-- pandas/tests/test_algos.py | 6 +- pandas/tests/test_sorting.py | 6 +- pandas/tests/test_take.py | 8 ++- .../tseries/frequencies/test_inference.py | 8 ++- pandas/tests/window/test_rolling.py | 8 ++- 15 files changed, 84 insertions(+), 69 deletions(-) diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index 3dbf49df72558..60d5d8c8ccaca 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -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() diff --git a/pandas/tests/frame/test_repr_info.py b/pandas/tests/frame/test_repr_info.py index e2cfc50510173..b288fafd8f7f6 100644 --- a/pandas/tests/frame/test_repr_info.py +++ b/pandas/tests/frame/test_repr_info.py @@ -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) diff --git a/pandas/tests/groupby/test_allowlist.py b/pandas/tests/groupby/test_allowlist.py index 8be721c13eea8..f1fc40ee7aba0 100644 --- a/pandas/tests/groupby/test_allowlist.py +++ b/pandas/tests/groupby/test_allowlist.py @@ -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"]] diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 94ecfe81abd45..c7c575b479988 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -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 @@ -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( @@ -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 diff --git a/pandas/tests/indexing/test_partial.py b/pandas/tests/indexing/test_partial.py index 7b2713ad274c6..c487777fc339e 100644 --- a/pandas/tests/indexing/test_partial.py +++ b/pandas/tests/indexing/test_partial.py @@ -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( diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index be99eb0bf0a69..8436c2db445ee 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -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"]] diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index 7e6c2a452f1a0..9b2e0cac5de84 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -1312,6 +1312,13 @@ 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), @@ -1319,21 +1326,15 @@ def test_add_offset(self): 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 @@ -1368,6 +1369,13 @@ 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), @@ -1375,21 +1383,14 @@ def test_add_offset(self): 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 @@ -1423,6 +1424,13 @@ 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), @@ -1430,27 +1438,26 @@ def test_add_offset(self): 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) diff --git a/pandas/tests/scalar/timedelta/test_arithmetic.py b/pandas/tests/scalar/timedelta/test_arithmetic.py index 7dfda0463ecaf..9c36d5777d60c 100644 --- a/pandas/tests/scalar/timedelta/test_arithmetic.py +++ b/pandas/tests/scalar/timedelta/test_arithmetic.py @@ -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 diff --git a/pandas/tests/series/indexing/test_getitem.py b/pandas/tests/series/indexing/test_getitem.py index da8de5c553f53..03b1c512f9053 100644 --- a/pandas/tests/series/indexing/test_getitem.py +++ b/pandas/tests/series/indexing/test_getitem.py @@ -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 @@ -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] diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index 8361ec6c6b5fa..a28da1d856cf9 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -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]: diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index 8f0991eb98bb5..779d6e6b6bb0f 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -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) diff --git a/pandas/tests/test_sorting.py b/pandas/tests/test_sorting.py index a49b7c2b7f86e..6a39638af9c87 100644 --- a/pandas/tests/test_sorting.py +++ b/pandas/tests/test_sorting.py @@ -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) diff --git a/pandas/tests/test_take.py b/pandas/tests/test_take.py index 4a2e3f971670e..f0737f7dc4cce 100644 --- a/pandas/tests/test_take.py +++ b/pandas/tests/test_take.py @@ -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) diff --git a/pandas/tests/tseries/frequencies/test_inference.py b/pandas/tests/tseries/frequencies/test_inference.py index e500517d82d4c..cbbe29fb6cf9a 100644 --- a/pandas/tests/tseries/frequencies/test_inference.py +++ b/pandas/tests/tseries/frequencies/test_inference.py @@ -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): diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index d58eeaa7cbcb1..74ee991b040d1 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -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)