Skip to content

Commit 6971c9c

Browse files
authored
CLN/TST: Remove old data creation methods in _testing/__init__.py (#56144)
* Clean up sparely used index generating methods * Remove makePeriodSeries * Remove from all * Remove makeIntervalIndex * Remove makeIntervalIndex * Cast as object
1 parent e84bd1c commit 6971c9c

File tree

9 files changed

+54
-115
lines changed

9 files changed

+54
-115
lines changed

pandas/_testing/__init__.py

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
DataFrame,
4444
DatetimeIndex,
4545
Index,
46-
IntervalIndex,
4746
MultiIndex,
4847
RangeIndex,
4948
Series,
@@ -106,8 +105,6 @@
106105
from pandas.core.construction import extract_array
107106

108107
if TYPE_CHECKING:
109-
from collections.abc import Iterable
110-
111108
from pandas._typing import (
112109
Dtype,
113110
Frequency,
@@ -388,12 +385,6 @@ def makeCategoricalIndex(
388385
)
389386

390387

391-
def makeIntervalIndex(k: int = 10, name=None, **kwargs) -> IntervalIndex:
392-
"""make a length k IntervalIndex"""
393-
x = np.linspace(0, 100, num=(k + 1))
394-
return IntervalIndex.from_breaks(x, name=name, **kwargs)
395-
396-
397388
def makeBoolIndex(k: int = 10, name=None) -> Index:
398389
if k == 1:
399390
return Index([True], name=name)
@@ -465,45 +456,6 @@ def makePeriodIndex(k: int = 10, name=None, **kwargs) -> PeriodIndex:
465456
return pi
466457

467458

468-
def makeMultiIndex(k: int = 10, names=None, **kwargs):
469-
N = (k // 2) + 1
470-
rng = range(N)
471-
mi = MultiIndex.from_product([("foo", "bar"), rng], names=names, **kwargs)
472-
assert len(mi) >= k # GH#38795
473-
return mi[:k]
474-
475-
476-
def index_subclass_makers_generator():
477-
make_index_funcs = [
478-
makeDateIndex,
479-
makePeriodIndex,
480-
makeTimedeltaIndex,
481-
makeRangeIndex,
482-
makeIntervalIndex,
483-
makeCategoricalIndex,
484-
makeMultiIndex,
485-
]
486-
yield from make_index_funcs
487-
488-
489-
def all_timeseries_index_generator(k: int = 10) -> Iterable[Index]:
490-
"""
491-
Generator which can be iterated over to get instances of all the classes
492-
which represent time-series.
493-
494-
Parameters
495-
----------
496-
k: length of each of the index instances
497-
"""
498-
make_index_funcs: list[Callable[..., Index]] = [
499-
makeDateIndex,
500-
makePeriodIndex,
501-
makeTimedeltaIndex,
502-
]
503-
for make_index_func in make_index_funcs:
504-
yield make_index_func(k=k)
505-
506-
507459
# make series
508460
def make_rand_series(name=None, dtype=np.float64) -> Series:
509461
index = makeStringIndex(_N)
@@ -546,24 +498,10 @@ def makeTimeSeries(nper=None, freq: Frequency = "B", name=None) -> Series:
546498
)
547499

548500

549-
def makePeriodSeries(nper=None, name=None) -> Series:
550-
if nper is None:
551-
nper = _N
552-
return Series(
553-
np.random.default_rng(2).standard_normal(nper),
554-
index=makePeriodIndex(nper),
555-
name=name,
556-
)
557-
558-
559501
def getTimeSeriesData(nper=None, freq: Frequency = "B") -> dict[str, Series]:
560502
return {c: makeTimeSeries(nper, freq) for c in getCols(_K)}
561503

562504

563-
def getPeriodData(nper=None) -> dict[str, Series]:
564-
return {c: makePeriodSeries(nper) for c in getCols(_K)}
565-
566-
567505
# make frame
568506
def makeTimeDataFrame(nper=None, freq: Frequency = "B") -> DataFrame:
569507
data = getTimeSeriesData(nper, freq)
@@ -592,11 +530,6 @@ def makeMixedDataFrame() -> DataFrame:
592530
return DataFrame(getMixedTypeDict()[1])
593531

594532

595-
def makePeriodFrame(nper=None) -> DataFrame:
596-
data = getPeriodData(nper)
597-
return DataFrame(data)
598-
599-
600533
def makeCustomIndex(
601534
nentries,
602535
nlevels,
@@ -1080,7 +1013,6 @@ def shares_memory(left, right) -> bool:
10801013
"ALL_INT_NUMPY_DTYPES",
10811014
"ALL_NUMPY_DTYPES",
10821015
"ALL_REAL_NUMPY_DTYPES",
1083-
"all_timeseries_index_generator",
10841016
"assert_almost_equal",
10851017
"assert_attr_equal",
10861018
"assert_categorical_equal",
@@ -1129,12 +1061,10 @@ def shares_memory(left, right) -> bool:
11291061
"get_finest_unit",
11301062
"get_obj",
11311063
"get_op_from_name",
1132-
"getPeriodData",
11331064
"getSeriesData",
11341065
"getTimeSeriesData",
11351066
"iat",
11361067
"iloc",
1137-
"index_subclass_makers_generator",
11381068
"loc",
11391069
"makeBoolIndex",
11401070
"makeCategoricalIndex",
@@ -1144,15 +1074,11 @@ def shares_memory(left, right) -> bool:
11441074
"makeDateIndex",
11451075
"makeFloatIndex",
11461076
"makeFloatSeries",
1147-
"makeIntervalIndex",
11481077
"makeIntIndex",
11491078
"makeMixedDataFrame",
1150-
"makeMultiIndex",
11511079
"makeNumericIndex",
11521080
"makeObjectSeries",
1153-
"makePeriodFrame",
11541081
"makePeriodIndex",
1155-
"makePeriodSeries",
11561082
"make_rand_series",
11571083
"makeRangeIndex",
11581084
"makeStringIndex",

pandas/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
from pandas import (
6262
DataFrame,
6363
Interval,
64+
IntervalIndex,
6465
Period,
6566
Series,
6667
Timedelta,
@@ -630,7 +631,7 @@ def _create_mi_with_dt64tz_level():
630631
"complex64": tm.makeNumericIndex(100, dtype="float64").astype("complex64"),
631632
"complex128": tm.makeNumericIndex(100, dtype="float64").astype("complex128"),
632633
"categorical": tm.makeCategoricalIndex(100),
633-
"interval": tm.makeIntervalIndex(100),
634+
"interval": IntervalIndex.from_breaks(np.linspace(0, 100, num=101)),
634635
"empty": Index([]),
635636
"tuples": MultiIndex.from_tuples(zip(["foo", "bar", "baz"], [1, 2, 3])),
636637
"mi-with-dt64tz-level": _create_mi_with_dt64tz_level(),

pandas/tests/dtypes/test_missing.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
Series,
4141
TimedeltaIndex,
4242
date_range,
43+
period_range,
4344
)
4445
import pandas._testing as tm
4546

@@ -81,7 +82,7 @@ def test_notna_notnull(notna_f):
8182
tm.makeStringSeries(),
8283
tm.makeObjectSeries(),
8384
tm.makeTimeSeries(),
84-
tm.makePeriodSeries(),
85+
Series(range(5), period_range("2020-01-01", periods=5)),
8586
],
8687
)
8788
def test_null_check_is_series(null_func, ser):
@@ -124,15 +125,25 @@ def test_isna_isnull(self, isna_f):
124125

125126
@pytest.mark.parametrize("isna_f", [isna, isnull])
126127
@pytest.mark.parametrize(
127-
"df",
128+
"data",
128129
[
129-
tm.makeTimeDataFrame(),
130-
tm.makePeriodFrame(),
131-
tm.makeMixedDataFrame(),
130+
np.arange(4, dtype=float),
131+
[0.0, 1.0, 0.0, 1.0],
132+
Series(list("abcd"), dtype=object),
133+
date_range("2020-01-01", periods=4),
132134
],
133135
)
134-
def test_isna_isnull_frame(self, isna_f, df):
136+
@pytest.mark.parametrize(
137+
"index",
138+
[
139+
date_range("2020-01-01", periods=4),
140+
range(4),
141+
period_range("2020-01-01", periods=4),
142+
],
143+
)
144+
def test_isna_isnull_frame(self, isna_f, data, index):
135145
# frame
146+
df = pd.DataFrame(data, index=index)
136147
result = isna_f(df)
137148
expected = df.apply(isna_f)
138149
tm.assert_frame_equal(result, expected)

pandas/tests/frame/methods/test_shift.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ def test_shift_by_offset(self, datetime_frame, frame_or_series):
241241

242242
def test_shift_with_periodindex(self, frame_or_series):
243243
# Shifting with PeriodIndex
244-
ps = tm.makePeriodFrame()
244+
ps = DataFrame(
245+
np.arange(4, dtype=float), index=pd.period_range("2020-01-01", periods=4)
246+
)
245247
ps = tm.get_obj(ps, frame_or_series)
246248

247249
shifted = ps.shift(1)
@@ -492,7 +494,7 @@ def test_shift_axis1_multiple_blocks_with_int_fill(self):
492494
tm.assert_frame_equal(result, expected)
493495

494496
def test_period_index_frame_shift_with_freq(self, frame_or_series):
495-
ps = tm.makePeriodFrame()
497+
ps = DataFrame(range(4), index=pd.period_range("2020-01-01", periods=4))
496498
ps = tm.get_obj(ps, frame_or_series)
497499

498500
shifted = ps.shift(1, freq="infer")
@@ -529,7 +531,7 @@ def test_datetime_frame_shift_with_freq(self, datetime_frame, frame_or_series):
529531
tm.assert_equal(unshifted, inferred_ts)
530532

531533
def test_period_index_frame_shift_with_freq_error(self, frame_or_series):
532-
ps = tm.makePeriodFrame()
534+
ps = DataFrame(range(4), index=pd.period_range("2020-01-01", periods=4))
533535
ps = tm.get_obj(ps, frame_or_series)
534536
msg = "Given freq M does not match PeriodIndex freq D"
535537
with pytest.raises(ValueError, match=msg):

pandas/tests/indexes/test_base.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections import defaultdict
22
from datetime import datetime
3+
from functools import partial
34
import math
45
import operator
56
import re
@@ -1596,11 +1597,23 @@ def test_generated_op_names(opname, index):
15961597
assert method.__name__ == opname
15971598

15981599

1599-
@pytest.mark.parametrize("index_maker", tm.index_subclass_makers_generator())
1600-
def test_index_subclass_constructor_wrong_kwargs(index_maker):
1600+
@pytest.mark.parametrize(
1601+
"klass",
1602+
[
1603+
partial(CategoricalIndex, data=[1]),
1604+
partial(DatetimeIndex, data=["2020-01-01"]),
1605+
partial(PeriodIndex, data=["2020-01-01"]),
1606+
partial(TimedeltaIndex, data=["1 day"]),
1607+
partial(RangeIndex, data=range(1)),
1608+
partial(IntervalIndex, data=[pd.Interval(0, 1)]),
1609+
partial(Index, data=["a"], dtype=object),
1610+
partial(MultiIndex, levels=[1], codes=[0]),
1611+
],
1612+
)
1613+
def test_index_subclass_constructor_wrong_kwargs(klass):
16011614
# GH #19348
16021615
with pytest.raises(TypeError, match="unexpected keyword argument"):
1603-
index_maker(foo="bar")
1616+
klass(foo="bar")
16041617

16051618

16061619
def test_deprecated_fastpath():

pandas/tests/plotting/test_datetimelike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def test_irregular_datetime64_repr_bug(self):
347347
assert rs == xp
348348

349349
def test_business_freq(self):
350-
bts = tm.makePeriodSeries()
350+
bts = Series(range(5), period_range("2020-01-01", periods=5))
351351
msg = r"PeriodDtype\[B\] is deprecated"
352352
dt = bts.index[0].to_timestamp()
353353
with tm.assert_produces_warning(FutureWarning, match=msg):

pandas/tests/plotting/test_series.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
DataFrame,
1515
Series,
1616
date_range,
17+
period_range,
1718
plotting,
1819
)
1920
import pandas._testing as tm
@@ -45,11 +46,6 @@ def series():
4546
return tm.makeStringSeries(name="series")
4647

4748

48-
@pytest.fixture
49-
def iseries():
50-
return tm.makePeriodSeries(name="iseries")
51-
52-
5349
class TestSeriesPlots:
5450
@pytest.mark.slow
5551
@pytest.mark.parametrize("kwargs", [{"label": "foo"}, {"use_index": False}])
@@ -82,8 +78,9 @@ def test_plot_ts_bar(self, ts):
8278
def test_plot_ts_area_stacked(self, ts):
8379
_check_plot_works(ts.plot.area, stacked=False)
8480

85-
def test_plot_iseries(self, iseries):
86-
_check_plot_works(iseries.plot)
81+
def test_plot_iseries(self):
82+
ser = Series(range(5), period_range("2020-01-01", periods=5))
83+
_check_plot_works(ser.plot)
8784

8885
@pytest.mark.parametrize(
8986
"kind",

pandas/tests/resample/test_base.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from pandas import (
77
DataFrame,
8+
DatetimeIndex,
89
Index,
910
MultiIndex,
1011
NaT,
@@ -288,16 +289,19 @@ def test_resample_size_empty_dataframe(freq, empty_frame_dti):
288289
tm.assert_series_equal(result, expected)
289290

290291

291-
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
292-
@pytest.mark.parametrize("index", tm.all_timeseries_index_generator(0))
292+
@pytest.mark.parametrize(
293+
"index",
294+
[
295+
PeriodIndex([], freq="M", name="a"),
296+
DatetimeIndex([], name="a"),
297+
TimedeltaIndex([], name="a"),
298+
],
299+
)
293300
@pytest.mark.parametrize("dtype", [float, int, object, "datetime64[ns]"])
294301
def test_resample_empty_dtypes(index, dtype, resample_method):
295302
# Empty series were sometimes causing a segfault (for the functions
296303
# with Cython bounds-checking disabled) or an IndexError. We just run
297304
# them to ensure they no longer do. (GH #10228)
298-
if isinstance(index, PeriodIndex):
299-
# GH#53511
300-
index = PeriodIndex([], freq="B", name=index.name)
301305
empty_series_dti = Series([], index, dtype)
302306
rs = empty_series_dti.resample("d", group_keys=False)
303307
try:

pandas/tests/util/test_make_objects.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)