Skip to content

Commit 7c6d26f

Browse files
authored
CLN/TST: Remove makeTimeSeries (#56293)
* CLN/TST: Remove makeTimeSeries * adjust test
1 parent 6f245e6 commit 7c6d26f

33 files changed

+322
-125
lines changed

pandas/_testing/__init__.py

-14
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,11 @@
101101
if TYPE_CHECKING:
102102
from pandas._typing import (
103103
Dtype,
104-
Frequency,
105104
NpDtype,
106105
)
107106

108107
from pandas.core.arrays import ArrowExtensionArray
109108

110-
_N = 30
111-
112109
UNSIGNED_INT_NUMPY_DTYPES: list[NpDtype] = ["uint8", "uint16", "uint32", "uint64"]
113110
UNSIGNED_INT_EA_DTYPES: list[Dtype] = ["UInt8", "UInt16", "UInt32", "UInt64"]
114111
SIGNED_INT_NUMPY_DTYPES: list[NpDtype] = [int, "int8", "int16", "int32", "int64"]
@@ -339,16 +336,6 @@ def to_array(obj):
339336
# Others
340337

341338

342-
def makeTimeSeries(nper=None, freq: Frequency = "B", name=None) -> Series:
343-
if nper is None:
344-
nper = _N
345-
return Series(
346-
np.random.default_rng(2).standard_normal(nper),
347-
index=date_range("2000-01-01", periods=nper, freq=freq),
348-
name=name,
349-
)
350-
351-
352339
def makeCustomIndex(
353340
nentries,
354341
nlevels,
@@ -883,7 +870,6 @@ def shares_memory(left, right) -> bool:
883870
"loc",
884871
"makeCustomDataframe",
885872
"makeCustomIndex",
886-
"makeTimeSeries",
887873
"maybe_produces_warning",
888874
"NARROW_NP_DTYPES",
889875
"NP_NAT_OBJECTS",

pandas/conftest.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,11 @@ def datetime_series() -> Series:
766766
"""
767767
Fixture for Series of floats with DatetimeIndex
768768
"""
769-
s = tm.makeTimeSeries()
770-
s.name = "ts"
771-
return s
769+
return Series(
770+
np.random.default_rng(2).standard_normal(30),
771+
index=date_range("2000-01-01", periods=30, freq="B"),
772+
name="ts",
773+
)
772774

773775

774776
def _create_series(index):

pandas/tests/apply/test_series_apply.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
MultiIndex,
99
Series,
1010
concat,
11+
date_range,
1112
timedelta_range,
1213
)
1314
import pandas._testing as tm
@@ -134,7 +135,7 @@ def foo2(x, b=2, c=0):
134135

135136
def test_series_apply_map_box_timestamps(by_row):
136137
# GH#2689, GH#2627
137-
ser = Series(pd.date_range("1/1/2000", periods=10))
138+
ser = Series(date_range("1/1/2000", periods=10))
138139

139140
def func(x):
140141
return (x.hour, x.day, x.month)
@@ -194,13 +195,11 @@ def test_apply_box_period():
194195

195196

196197
def test_apply_datetimetz(by_row):
197-
values = pd.date_range("2011-01-01", "2011-01-02", freq="h").tz_localize(
198-
"Asia/Tokyo"
199-
)
198+
values = date_range("2011-01-01", "2011-01-02", freq="h").tz_localize("Asia/Tokyo")
200199
s = Series(values, name="XX")
201200

202201
result = s.apply(lambda x: x + pd.offsets.Day(), by_row=by_row)
203-
exp_values = pd.date_range("2011-01-02", "2011-01-03", freq="h").tz_localize(
202+
exp_values = date_range("2011-01-02", "2011-01-03", freq="h").tz_localize(
204203
"Asia/Tokyo"
205204
)
206205
exp = Series(exp_values, name="XX")
@@ -267,7 +266,7 @@ def test_apply_categorical_with_nan_values(series, by_row):
267266

268267
def test_apply_empty_integer_series_with_datetime_index(by_row):
269268
# GH 21245
270-
s = Series([], index=pd.date_range(start="2018-01-01", periods=0), dtype=int)
269+
s = Series([], index=date_range(start="2018-01-01", periods=0), dtype=int)
271270
result = s.apply(lambda x: x, by_row=by_row)
272271
tm.assert_series_equal(result, s)
273272

@@ -510,8 +509,12 @@ def test_series_apply_no_suffix_index(by_row):
510509
DataFrame(np.repeat([[1, 2]], 2, axis=0), dtype="int64"),
511510
),
512511
(
513-
tm.makeTimeSeries(nper=30),
514-
DataFrame(np.repeat([[1, 2]], 30, axis=0), dtype="int64"),
512+
Series(
513+
np.arange(10, dtype=np.float64),
514+
index=date_range("2020-01-01", periods=10),
515+
name="ts",
516+
),
517+
DataFrame(np.repeat([[1, 2]], 10, axis=0), dtype="int64"),
515518
),
516519
],
517520
)
@@ -528,12 +531,15 @@ def test_apply_series_on_date_time_index_aware_series(dti, exp, aware):
528531

529532

530533
@pytest.mark.parametrize(
531-
"by_row, expected", [("compat", Series(np.ones(30), dtype="int64")), (False, 1)]
534+
"by_row, expected", [("compat", Series(np.ones(10), dtype="int64")), (False, 1)]
532535
)
533536
def test_apply_scalar_on_date_time_index_aware_series(by_row, expected):
534537
# GH 25959
535538
# Calling apply on a localized time series should not cause an error
536-
series = tm.makeTimeSeries(nper=30).tz_localize("UTC")
539+
series = Series(
540+
np.arange(10, dtype=np.float64),
541+
index=date_range("2020-01-01", periods=10, tz="UTC"),
542+
)
537543
result = Series(series.index).apply(lambda x: 1, by_row=by_row)
538544
tm.assert_equal(result, expected)
539545

pandas/tests/arithmetic/test_numeric.py

+35-11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Timedelta,
2020
TimedeltaIndex,
2121
array,
22+
date_range,
2223
)
2324
import pandas._testing as tm
2425
from pandas.core import ops
@@ -733,7 +734,7 @@ def test_mul_datelike_raises(self, numeric_idx):
733734
idx = numeric_idx
734735
msg = "cannot perform __rmul__ with this index type"
735736
with pytest.raises(TypeError, match=msg):
736-
idx * pd.date_range("20130101", periods=5)
737+
idx * date_range("20130101", periods=5)
737738

738739
def test_mul_size_mismatch_raises(self, numeric_idx):
739740
idx = numeric_idx
@@ -820,7 +821,11 @@ def test_ops_np_scalar(self, other):
820821
# TODO: This came from series.test.test_operators, needs cleanup
821822
def test_operators_frame(self):
822823
# rpow does not work with DataFrame
823-
ts = tm.makeTimeSeries()
824+
ts = Series(
825+
np.arange(10, dtype=np.float64),
826+
index=date_range("2020-01-01", periods=10),
827+
name="ts",
828+
)
824829
ts.name = "ts"
825830

826831
df = pd.DataFrame({"A": ts})
@@ -926,8 +931,11 @@ def test_series_frame_radd_bug(self, fixed_now_ts):
926931
expected = pd.DataFrame({"vals": vals.map(lambda x: "foo_" + x)})
927932
tm.assert_frame_equal(result, expected)
928933

929-
ts = tm.makeTimeSeries()
930-
ts.name = "ts"
934+
ts = Series(
935+
np.arange(10, dtype=np.float64),
936+
index=date_range("2020-01-01", periods=10),
937+
name="ts",
938+
)
931939

932940
# really raise this time
933941
fix_now = fixed_now_ts.to_pydatetime()
@@ -955,8 +963,8 @@ def test_datetime64_with_index(self):
955963
# GH#4629
956964
# arithmetic datetime64 ops with an index
957965
ser = Series(
958-
pd.date_range("20130101", periods=5),
959-
index=pd.date_range("20130101", periods=5),
966+
date_range("20130101", periods=5),
967+
index=date_range("20130101", periods=5),
960968
)
961969
expected = ser - ser.index.to_series()
962970
result = ser - ser.index
@@ -969,7 +977,7 @@ def test_datetime64_with_index(self):
969977

970978
df = pd.DataFrame(
971979
np.random.default_rng(2).standard_normal((5, 2)),
972-
index=pd.date_range("20130101", periods=5),
980+
index=date_range("20130101", periods=5),
973981
)
974982
df["date"] = pd.Timestamp("20130102")
975983
df["expected"] = df["date"] - df.index.to_series()
@@ -1031,7 +1039,11 @@ def test_frame_operators_empty_like(self, dtype):
10311039
)
10321040
def test_series_operators_arithmetic(self, all_arithmetic_functions, func):
10331041
op = all_arithmetic_functions
1034-
series = tm.makeTimeSeries().rename("ts")
1042+
series = Series(
1043+
np.arange(10, dtype=np.float64),
1044+
index=date_range("2020-01-01", periods=10),
1045+
name="ts",
1046+
)
10351047
other = func(series)
10361048
compare_op(series, other, op)
10371049

@@ -1040,7 +1052,11 @@ def test_series_operators_arithmetic(self, all_arithmetic_functions, func):
10401052
)
10411053
def test_series_operators_compare(self, comparison_op, func):
10421054
op = comparison_op
1043-
series = tm.makeTimeSeries().rename("ts")
1055+
series = Series(
1056+
np.arange(10, dtype=np.float64),
1057+
index=date_range("2020-01-01", periods=10),
1058+
name="ts",
1059+
)
10441060
other = func(series)
10451061
compare_op(series, other, op)
10461062

@@ -1050,7 +1066,11 @@ def test_series_operators_compare(self, comparison_op, func):
10501066
ids=["multiply", "slice", "constant"],
10511067
)
10521068
def test_divmod(self, func):
1053-
series = tm.makeTimeSeries().rename("ts")
1069+
series = Series(
1070+
np.arange(10, dtype=np.float64),
1071+
index=date_range("2020-01-01", periods=10),
1072+
name="ts",
1073+
)
10541074
other = func(series)
10551075
results = divmod(series, other)
10561076
if isinstance(other, abc.Iterable) and len(series) != len(other):
@@ -1081,7 +1101,11 @@ def test_series_divmod_zero(self):
10811101
# -1/0 == -np.inf
10821102
# 1/-0.0 == -np.inf
10831103
# -1/-0.0 == np.inf
1084-
tser = tm.makeTimeSeries().rename("ts")
1104+
tser = Series(
1105+
np.arange(1, 11, dtype=np.float64),
1106+
index=date_range("2020-01-01", periods=10),
1107+
name="ts",
1108+
)
10851109
other = tser * 0
10861110

10871111
result = divmod(tser, other)

pandas/tests/frame/methods/test_reindex.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,9 @@ def test_reindex_sparse(self):
609609
tm.assert_frame_equal(result, expected)
610610

611611
def test_reindex(self, float_frame, using_copy_on_write):
612-
datetime_series = tm.makeTimeSeries(nper=30)
612+
datetime_series = Series(
613+
np.arange(30, dtype=np.float64), index=date_range("2020-01-01", periods=30)
614+
)
613615

614616
newFrame = float_frame.reindex(datetime_series.index)
615617

pandas/tests/frame/test_constructors.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,11 @@ def test_constructor_ordereddict(self):
500500
assert expected == list(df.columns)
501501

502502
def test_constructor_dict(self):
503-
datetime_series = tm.makeTimeSeries(nper=30)
503+
datetime_series = Series(
504+
np.arange(30, dtype=np.float64), index=date_range("2020-01-01", periods=30)
505+
)
504506
# test expects index shifted by 5
505-
datetime_series_short = tm.makeTimeSeries(nper=30)[5:]
507+
datetime_series_short = datetime_series[5:]
506508

507509
frame = DataFrame({"col1": datetime_series, "col2": datetime_series_short})
508510

@@ -626,8 +628,10 @@ def test_constructor_dict_nan_tuple_key(self, value):
626628
tm.assert_frame_equal(result, expected)
627629

628630
def test_constructor_dict_order_insertion(self):
629-
datetime_series = tm.makeTimeSeries(nper=30)
630-
datetime_series_short = tm.makeTimeSeries(nper=25)
631+
datetime_series = Series(
632+
np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
633+
)
634+
datetime_series_short = datetime_series[:5]
631635

632636
# GH19018
633637
# initialization ordering: by insertion order if python>= 3.6

pandas/tests/groupby/aggregate/test_other.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,9 @@ def raiseException(df):
296296

297297

298298
def test_series_agg_multikey():
299-
ts = tm.makeTimeSeries()
299+
ts = Series(
300+
np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
301+
)
300302
grouped = ts.groupby([lambda x: x.year, lambda x: x.month])
301303

302304
result = grouped.agg("sum")

pandas/tests/groupby/conftest.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from pandas import (
55
DataFrame,
66
Index,
7+
Series,
78
date_range,
89
)
9-
import pandas._testing as tm
1010
from pandas.core.groupby.base import (
1111
reduction_kernels,
1212
transformation_kernels,
@@ -47,7 +47,10 @@ def df():
4747

4848
@pytest.fixture
4949
def ts():
50-
return tm.makeTimeSeries()
50+
return Series(
51+
np.random.default_rng(2).standard_normal(30),
52+
index=date_range("2000-01-01", periods=30, freq="B"),
53+
)
5154

5255

5356
@pytest.fixture

pandas/tests/groupby/methods/test_describe.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
DataFrame,
77
Index,
88
MultiIndex,
9+
Series,
910
Timestamp,
11+
date_range,
1012
)
1113
import pandas._testing as tm
1214

@@ -17,7 +19,9 @@ def test_apply_describe_bug(multiindex_dataframe_random_data):
1719

1820

1921
def test_series_describe_multikey():
20-
ts = tm.makeTimeSeries()
22+
ts = Series(
23+
np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
24+
)
2125
grouped = ts.groupby([lambda x: x.year, lambda x: x.month])
2226
result = grouped.describe()
2327
tm.assert_series_equal(result["mean"], grouped.mean(), check_names=False)
@@ -26,7 +30,9 @@ def test_series_describe_multikey():
2630

2731

2832
def test_series_describe_single():
29-
ts = tm.makeTimeSeries()
33+
ts = Series(
34+
np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
35+
)
3036
grouped = ts.groupby(lambda x: x.month)
3137
result = grouped.apply(lambda x: x.describe())
3238
expected = grouped.describe().stack(future_stack=True)

pandas/tests/io/formats/test_to_string.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,10 @@ def test_to_string_timedelta64(self):
10751075
assert result == "0 1 days\n1 2 days\n2 3 days"
10761076

10771077
def test_to_string(self):
1078-
ts = tm.makeTimeSeries()
1078+
ts = Series(
1079+
np.arange(10, dtype=np.float64),
1080+
index=date_range("2020-01-01", periods=10, freq="B"),
1081+
)
10791082
buf = StringIO()
10801083

10811084
s = ts.to_string()

pandas/tests/io/json/test_pandas.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ def categorical_frame(self):
108108
def datetime_series(self):
109109
# Same as usual datetime_series, but with index freq set to None,
110110
# since that doesn't round-trip, see GH#33711
111-
ser = tm.makeTimeSeries()
112-
ser.name = "ts"
111+
ser = Series(
112+
1.1 * np.arange(10, dtype=np.float64),
113+
index=date_range("2020-01-01", periods=10),
114+
name="ts",
115+
)
113116
ser.index = ser.index._with_freq(None)
114117
return ser
115118

pandas/tests/io/pytables/test_append.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ def test_append_series(setup_path):
105105
with ensure_clean_store(setup_path) as store:
106106
# basic
107107
ss = Series(range(20), dtype=np.float64, index=[f"i_{i}" for i in range(20)])
108-
ts = tm.makeTimeSeries()
108+
ts = Series(
109+
np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
110+
)
109111
ns = Series(np.arange(100))
110112

111113
store.append("ss", ss)

0 commit comments

Comments
 (0)