From 72b798d3e87b35bf621c5b1a4fd8b3ba08913bfa Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 23 Nov 2023 20:13:12 -0800 Subject: [PATCH] Remove makePeriodSeries --- pandas/_testing/__init__.py | 22 --------------------- pandas/tests/dtypes/test_missing.py | 23 ++++++++++++++++------ pandas/tests/frame/methods/test_shift.py | 8 +++++--- pandas/tests/plotting/test_datetimelike.py | 2 +- pandas/tests/plotting/test_series.py | 11 ++++------- 5 files changed, 27 insertions(+), 39 deletions(-) diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index a0a409ada523f..b08d299874d79 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -519,24 +519,10 @@ def makeTimeSeries(nper=None, freq: Frequency = "B", name=None) -> Series: ) -def makePeriodSeries(nper=None, name=None) -> Series: - if nper is None: - nper = _N - return Series( - np.random.default_rng(2).standard_normal(nper), - index=makePeriodIndex(nper), - name=name, - ) - - def getTimeSeriesData(nper=None, freq: Frequency = "B") -> dict[str, Series]: return {c: makeTimeSeries(nper, freq) for c in getCols(_K)} -def getPeriodData(nper=None) -> dict[str, Series]: - return {c: makePeriodSeries(nper) for c in getCols(_K)} - - # make frame def makeTimeDataFrame(nper=None, freq: Frequency = "B") -> DataFrame: data = getTimeSeriesData(nper, freq) @@ -565,11 +551,6 @@ def makeMixedDataFrame() -> DataFrame: return DataFrame(getMixedTypeDict()[1]) -def makePeriodFrame(nper=None) -> DataFrame: - data = getPeriodData(nper) - return DataFrame(data) - - def makeCustomIndex( nentries, nlevels, @@ -1102,7 +1083,6 @@ def shares_memory(left, right) -> bool: "get_finest_unit", "get_obj", "get_op_from_name", - "getPeriodData", "getSeriesData", "getTimeSeriesData", "iat", @@ -1122,9 +1102,7 @@ def shares_memory(left, right) -> bool: "makeMultiIndex", "makeNumericIndex", "makeObjectSeries", - "makePeriodFrame", "makePeriodIndex", - "makePeriodSeries", "make_rand_series", "makeRangeIndex", "makeStringIndex", diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index 1cc1e2725b9c7..44022ea7c6105 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -40,6 +40,7 @@ Series, TimedeltaIndex, date_range, + period_range, ) import pandas._testing as tm @@ -81,7 +82,7 @@ def test_notna_notnull(notna_f): tm.makeStringSeries(), tm.makeObjectSeries(), tm.makeTimeSeries(), - tm.makePeriodSeries(), + Series(range(5), period_range("2020-01-01", periods=5)), ], ) def test_null_check_is_series(null_func, ser): @@ -124,15 +125,25 @@ def test_isna_isnull(self, isna_f): @pytest.mark.parametrize("isna_f", [isna, isnull]) @pytest.mark.parametrize( - "df", + "data", [ - tm.makeTimeDataFrame(), - tm.makePeriodFrame(), - tm.makeMixedDataFrame(), + np.arange(4, dtype=float), + [0.0, 1.0, 0.0, 1.0], + list("abcd"), + date_range("2020-01-01", periods=4), ], ) - def test_isna_isnull_frame(self, isna_f, df): + @pytest.mark.parametrize( + "index", + [ + date_range("2020-01-01", periods=4), + range(4), + period_range("2020-01-01", periods=4), + ], + ) + def test_isna_isnull_frame(self, isna_f, data, index): # frame + df = pd.DataFrame(data, index=index) result = isna_f(df) expected = df.apply(isna_f) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_shift.py b/pandas/tests/frame/methods/test_shift.py index 98edd44e9f700..b21aa2d687682 100644 --- a/pandas/tests/frame/methods/test_shift.py +++ b/pandas/tests/frame/methods/test_shift.py @@ -241,7 +241,9 @@ def test_shift_by_offset(self, datetime_frame, frame_or_series): def test_shift_with_periodindex(self, frame_or_series): # Shifting with PeriodIndex - ps = tm.makePeriodFrame() + ps = DataFrame( + np.arange(4, dtype=float), index=pd.period_range("2020-01-01", periods=4) + ) ps = tm.get_obj(ps, frame_or_series) shifted = ps.shift(1) @@ -492,7 +494,7 @@ def test_shift_axis1_multiple_blocks_with_int_fill(self): tm.assert_frame_equal(result, expected) def test_period_index_frame_shift_with_freq(self, frame_or_series): - ps = tm.makePeriodFrame() + ps = DataFrame(range(4), index=pd.period_range("2020-01-01", periods=4)) ps = tm.get_obj(ps, frame_or_series) shifted = ps.shift(1, freq="infer") @@ -529,7 +531,7 @@ def test_datetime_frame_shift_with_freq(self, datetime_frame, frame_or_series): tm.assert_equal(unshifted, inferred_ts) def test_period_index_frame_shift_with_freq_error(self, frame_or_series): - ps = tm.makePeriodFrame() + ps = DataFrame(range(4), index=pd.period_range("2020-01-01", periods=4)) ps = tm.get_obj(ps, frame_or_series) msg = "Given freq M does not match PeriodIndex freq D" with pytest.raises(ValueError, match=msg): diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 0f66d94535053..bfb9a5a9a1647 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -347,7 +347,7 @@ def test_irregular_datetime64_repr_bug(self): assert rs == xp def test_business_freq(self): - bts = tm.makePeriodSeries() + bts = Series(range(5), period_range("2020-01-01", periods=5)) msg = r"PeriodDtype\[B\] is deprecated" dt = bts.index[0].to_timestamp() with tm.assert_produces_warning(FutureWarning, match=msg): diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index f78f5c4879b9f..7d543d29c034d 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -14,6 +14,7 @@ DataFrame, Series, date_range, + period_range, plotting, ) import pandas._testing as tm @@ -45,11 +46,6 @@ def series(): return tm.makeStringSeries(name="series") -@pytest.fixture -def iseries(): - return tm.makePeriodSeries(name="iseries") - - class TestSeriesPlots: @pytest.mark.slow @pytest.mark.parametrize("kwargs", [{"label": "foo"}, {"use_index": False}]) @@ -82,8 +78,9 @@ def test_plot_ts_bar(self, ts): def test_plot_ts_area_stacked(self, ts): _check_plot_works(ts.plot.area, stacked=False) - def test_plot_iseries(self, iseries): - _check_plot_works(iseries.plot) + def test_plot_iseries(self): + ser = Series(range(5), period_range("2020-01-01", periods=5)) + _check_plot_works(ser.plot) @pytest.mark.parametrize( "kind",