Skip to content

Commit 00a0216

Browse files
authored
TST/CLN: Remove getSeriesData/makeObjectSeries/makeDatetimeIndex (#56241)
* Remove makeObjectSeries * Remove makeDatetimeIndex * Remove makeDataFrame * Remove getSeriesData * use 2000 instead of 2020 * Just use ones DF
1 parent 4a06c0f commit 00a0216

22 files changed

+115
-240
lines changed

pandas/_testing/__init__.py

+1-35
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import collections
44
from collections import Counter
5-
from datetime import datetime
65
from decimal import Decimal
76
import operator
87
import os
@@ -36,12 +35,10 @@
3635
ArrowDtype,
3736
Categorical,
3837
DataFrame,
39-
DatetimeIndex,
4038
Index,
4139
MultiIndex,
4240
RangeIndex,
4341
Series,
44-
bdate_range,
4542
date_range,
4643
period_range,
4744
timedelta_range,
@@ -348,34 +345,12 @@ def getCols(k) -> str:
348345
return string.ascii_uppercase[:k]
349346

350347

351-
def makeDateIndex(
352-
k: int = 10, freq: Frequency = "B", name=None, **kwargs
353-
) -> DatetimeIndex:
354-
dt = datetime(2000, 1, 1)
355-
dr = bdate_range(dt, periods=k, freq=freq, name=name)
356-
return DatetimeIndex(dr, name=name, **kwargs)
357-
358-
359-
def makeObjectSeries(name=None) -> Series:
360-
data = [f"foo_{i}" for i in range(_N)]
361-
index = Index([f"bar_{i}" for i in range(_N)])
362-
return Series(data, index=index, name=name, dtype=object)
363-
364-
365-
def getSeriesData() -> dict[str, Series]:
366-
index = Index([f"foo_{i}" for i in range(_N)])
367-
return {
368-
c: Series(np.random.default_rng(i).standard_normal(_N), index=index)
369-
for i, c in enumerate(getCols(_K))
370-
}
371-
372-
373348
def makeTimeSeries(nper=None, freq: Frequency = "B", name=None) -> Series:
374349
if nper is None:
375350
nper = _N
376351
return Series(
377352
np.random.default_rng(2).standard_normal(nper),
378-
index=makeDateIndex(nper, freq=freq),
353+
index=date_range("2000-01-01", periods=nper, freq=freq),
379354
name=name,
380355
)
381356

@@ -390,11 +365,6 @@ def makeTimeDataFrame(nper=None, freq: Frequency = "B") -> DataFrame:
390365
return DataFrame(data)
391366

392367

393-
def makeDataFrame() -> DataFrame:
394-
data = getSeriesData()
395-
return DataFrame(data)
396-
397-
398368
def makeCustomIndex(
399369
nentries,
400370
nlevels,
@@ -925,16 +895,12 @@ def shares_memory(left, right) -> bool:
925895
"get_finest_unit",
926896
"get_obj",
927897
"get_op_from_name",
928-
"getSeriesData",
929898
"getTimeSeriesData",
930899
"iat",
931900
"iloc",
932901
"loc",
933902
"makeCustomDataframe",
934903
"makeCustomIndex",
935-
"makeDataFrame",
936-
"makeDateIndex",
937-
"makeObjectSeries",
938904
"makeTimeDataFrame",
939905
"makeTimeSeries",
940906
"maybe_produces_warning",

pandas/conftest.py

+19-48
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
Series,
6969
Timedelta,
7070
Timestamp,
71+
date_range,
7172
period_range,
7273
timedelta_range,
7374
)
@@ -608,15 +609,15 @@ def _create_mi_with_dt64tz_level():
608609
"""
609610
# GH#8367 round trip with pickle
610611
return MultiIndex.from_product(
611-
[[1, 2], ["a", "b"], pd.date_range("20130101", periods=3, tz="US/Eastern")],
612+
[[1, 2], ["a", "b"], date_range("20130101", periods=3, tz="US/Eastern")],
612613
names=["one", "two", "three"],
613614
)
614615

615616

616617
indices_dict = {
617618
"string": Index([f"pandas_{i}" for i in range(100)]),
618-
"datetime": tm.makeDateIndex(100),
619-
"datetime-tz": tm.makeDateIndex(100, tz="US/Pacific"),
619+
"datetime": date_range("2020-01-01", periods=100),
620+
"datetime-tz": date_range("2020-01-01", periods=100, tz="US/Pacific"),
620621
"period": period_range("2020-01-01", periods=100, freq="D"),
621622
"timedelta": timedelta_range(start="1 day", periods=100, freq="D"),
622623
"range": RangeIndex(100),
@@ -631,7 +632,7 @@ def _create_mi_with_dt64tz_level():
631632
"float32": Index(np.arange(100), dtype="float32"),
632633
"float64": Index(np.arange(100), dtype="float64"),
633634
"bool-object": Index([True, False] * 5, dtype=object),
634-
"bool-dtype": Index(np.random.default_rng(2).standard_normal(10) < 0),
635+
"bool-dtype": Index([True, False] * 5, dtype=bool),
635636
"complex64": Index(
636637
np.arange(100, dtype="complex64") + 1.0j * np.arange(100, dtype="complex64")
637638
),
@@ -751,9 +752,9 @@ def object_series() -> Series:
751752
"""
752753
Fixture for Series of dtype object with Index of unique strings
753754
"""
754-
s = tm.makeObjectSeries()
755-
s.name = "objects"
756-
return s
755+
data = [f"foo_{i}" for i in range(30)]
756+
index = Index([f"bar_{i}" for i in range(30)], dtype=object)
757+
return Series(data, index=index, name="objects", dtype=object)
757758

758759

759760
@pytest.fixture
@@ -839,27 +840,12 @@ def int_frame() -> DataFrame:
839840
Fixture for DataFrame of ints with index of unique strings
840841
841842
Columns are ['A', 'B', 'C', 'D']
842-
843-
A B C D
844-
vpBeWjM651 1 0 1 0
845-
5JyxmrP1En -1 0 0 0
846-
qEDaoD49U2 -1 1 0 0
847-
m66TkTfsFe 0 0 0 0
848-
EHPaNzEUFm -1 0 -1 0
849-
fpRJCevQhi 2 0 0 0
850-
OlQvnmfi3Q 0 0 -2 0
851-
... .. .. .. ..
852-
uB1FPlz4uP 0 0 0 1
853-
EcSe6yNzCU 0 0 -1 0
854-
L50VudaiI8 -1 1 -2 0
855-
y3bpw4nwIp 0 -1 0 0
856-
H0RdLLwrCT 1 1 0 0
857-
rY82K0vMwm 0 0 0 0
858-
1OPIUjnkjk 2 0 0 0
859-
860-
[30 rows x 4 columns]
861843
"""
862-
return DataFrame(tm.getSeriesData()).astype("int64")
844+
return DataFrame(
845+
np.ones((30, 4), dtype=np.int64),
846+
index=Index([f"foo_{i}" for i in range(30)], dtype=object),
847+
columns=Index(list("ABCD"), dtype=object),
848+
)
863849

864850

865851
@pytest.fixture
@@ -868,27 +854,12 @@ def float_frame() -> DataFrame:
868854
Fixture for DataFrame of floats with index of unique strings
869855
870856
Columns are ['A', 'B', 'C', 'D'].
871-
872-
A B C D
873-
P7GACiRnxd -0.465578 -0.361863 0.886172 -0.053465
874-
qZKh6afn8n -0.466693 -0.373773 0.266873 1.673901
875-
tkp0r6Qble 0.148691 -0.059051 0.174817 1.598433
876-
wP70WOCtv8 0.133045 -0.581994 -0.992240 0.261651
877-
M2AeYQMnCz -1.207959 -0.185775 0.588206 0.563938
878-
QEPzyGDYDo -0.381843 -0.758281 0.502575 -0.565053
879-
r78Jwns6dn -0.653707 0.883127 0.682199 0.206159
880-
... ... ... ... ...
881-
IHEGx9NO0T -0.277360 0.113021 -1.018314 0.196316
882-
lPMj8K27FA -1.313667 -0.604776 -1.305618 -0.863999
883-
qa66YMWQa5 1.110525 0.475310 -0.747865 0.032121
884-
yOa0ATsmcE -0.431457 0.067094 0.096567 -0.264962
885-
65znX3uRNG 1.528446 0.160416 -0.109635 -0.032987
886-
eCOBvKqf3e 0.235281 1.622222 0.781255 0.392871
887-
xSucinXxuV -1.263557 0.252799 -0.552247 0.400426
888-
889-
[30 rows x 4 columns]
890-
"""
891-
return DataFrame(tm.getSeriesData())
857+
"""
858+
return DataFrame(
859+
np.random.default_rng(2).standard_normal((30, 4)),
860+
index=Index([f"foo_{i}" for i in range(30)], dtype=object),
861+
columns=Index(list("ABCD"), dtype=object),
862+
)
892863

893864

894865
@pytest.fixture

pandas/tests/apply/test_numba.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ def test_numba_vs_python_indexing():
6060
"reduction",
6161
[lambda x: x.mean(), lambda x: x.min(), lambda x: x.max(), lambda x: x.sum()],
6262
)
63-
def test_numba_vs_python_reductions(float_frame, reduction, apply_axis):
64-
result = float_frame.apply(reduction, engine="numba", axis=apply_axis)
65-
expected = float_frame.apply(reduction, engine="python", axis=apply_axis)
63+
def test_numba_vs_python_reductions(reduction, apply_axis):
64+
df = DataFrame(np.ones((4, 4), dtype=np.float64))
65+
result = df.apply(reduction, engine="numba", axis=apply_axis)
66+
expected = df.apply(reduction, engine="python", axis=apply_axis)
6667
tm.assert_series_equal(result, expected)
6768

6869

pandas/tests/arithmetic/test_datetime64.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def test_dt64_compare_datetime_scalar(self, datetimelike, op, expected):
394394
class TestDatetimeIndexComparisons:
395395
# TODO: moved from tests.indexes.test_base; parametrize and de-duplicate
396396
def test_comparators(self, comparison_op):
397-
index = tm.makeDateIndex(100)
397+
index = date_range("2020-01-01", periods=10)
398398
element = index[len(index) // 2]
399399
element = Timestamp(element).to_datetime64()
400400

pandas/tests/arithmetic/test_object.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ def test_objarr_add_invalid(self, op, box_with_array):
169169
# invalid ops
170170
box = box_with_array
171171

172-
obj_ser = tm.makeObjectSeries()
173-
obj_ser.name = "objects"
172+
obj_ser = Series(list("abc"), dtype=object, name="objects")
174173

175174
obj_ser = tm.box_expected(obj_ser, box)
176175
msg = "|".join(

pandas/tests/dtypes/test_missing.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ def test_notna_notnull(notna_f):
7878
@pytest.mark.parametrize(
7979
"ser",
8080
[
81-
tm.makeObjectSeries(),
82-
tm.makeTimeSeries(),
81+
Series(
82+
[str(i) for i in range(5)],
83+
index=Index([str(i) for i in range(5)], dtype=object),
84+
dtype=object,
85+
),
86+
Series(range(5), date_range("2020-01-01", periods=5)),
8387
Series(range(5), period_range("2020-01-01", periods=5)),
8488
],
8589
)

pandas/tests/frame/conftest.py

+24-69
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from pandas import (
55
DataFrame,
6+
Index,
67
NaT,
78
date_range,
89
)
@@ -44,27 +45,12 @@ def float_string_frame():
4445
Fixture for DataFrame of floats and strings with index of unique strings
4546
4647
Columns are ['A', 'B', 'C', 'D', 'foo'].
47-
48-
A B C D foo
49-
w3orJvq07g -1.594062 -1.084273 -1.252457 0.356460 bar
50-
PeukuVdmz2 0.109855 -0.955086 -0.809485 0.409747 bar
51-
ahp2KvwiM8 -1.533729 -0.142519 -0.154666 1.302623 bar
52-
3WSJ7BUCGd 2.484964 0.213829 0.034778 -2.327831 bar
53-
khdAmufk0U -0.193480 -0.743518 -0.077987 0.153646 bar
54-
LE2DZiFlrE -0.193566 -1.343194 -0.107321 0.959978 bar
55-
HJXSJhVn7b 0.142590 1.257603 -0.659409 -0.223844 bar
56-
... ... ... ... ... ...
57-
9a1Vypttgw -1.316394 1.601354 0.173596 1.213196 bar
58-
h5d1gVFbEy 0.609475 1.106738 -0.155271 0.294630 bar
59-
mK9LsTQG92 1.303613 0.857040 -1.019153 0.369468 bar
60-
oOLksd9gKH 0.558219 -0.134491 -0.289869 -0.951033 bar
61-
9jgoOjKyHg 0.058270 -0.496110 -0.413212 -0.852659 bar
62-
jZLDHclHAO 0.096298 1.267510 0.549206 -0.005235 bar
63-
lR0nxDp1C2 -2.119350 -0.794384 0.544118 0.145849 bar
64-
65-
[30 rows x 5 columns]
6648
"""
67-
df = DataFrame(tm.getSeriesData())
49+
df = DataFrame(
50+
np.random.default_rng(2).standard_normal((30, 4)),
51+
index=Index([f"foo_{i}" for i in range(30)], dtype=object),
52+
columns=Index(list("ABCD"), dtype=object),
53+
)
6854
df["foo"] = "bar"
6955
return df
7056

@@ -75,31 +61,18 @@ def mixed_float_frame():
7561
Fixture for DataFrame of different float types with index of unique strings
7662
7763
Columns are ['A', 'B', 'C', 'D'].
78-
79-
A B C D
80-
GI7bbDaEZe -0.237908 -0.246225 -0.468506 0.752993
81-
KGp9mFepzA -1.140809 -0.644046 -1.225586 0.801588
82-
VeVYLAb1l2 -1.154013 -1.677615 0.690430 -0.003731
83-
kmPME4WKhO 0.979578 0.998274 -0.776367 0.897607
84-
CPyopdXTiz 0.048119 -0.257174 0.836426 0.111266
85-
0kJZQndAj0 0.274357 -0.281135 -0.344238 0.834541
86-
tqdwQsaHG8 -0.979716 -0.519897 0.582031 0.144710
87-
... ... ... ... ...
88-
7FhZTWILQj -2.906357 1.261039 -0.780273 -0.537237
89-
4pUDPM4eGq -2.042512 -0.464382 -0.382080 1.132612
90-
B8dUgUzwTi -1.506637 -0.364435 1.087891 0.297653
91-
hErlVYjVv9 1.477453 -0.495515 -0.713867 1.438427
92-
1BKN3o7YLs 0.127535 -0.349812 -0.881836 0.489827
93-
9S4Ekn7zga 1.445518 -2.095149 0.031982 0.373204
94-
xN1dNn6OV6 1.425017 -0.983995 -0.363281 -0.224502
95-
96-
[30 rows x 4 columns]
9764
"""
98-
df = DataFrame(tm.getSeriesData())
99-
df.A = df.A.astype("float32")
100-
df.B = df.B.astype("float32")
101-
df.C = df.C.astype("float16")
102-
df.D = df.D.astype("float64")
65+
df = DataFrame(
66+
{
67+
col: np.random.default_rng(2).random(30, dtype=dtype)
68+
for col, dtype in zip(
69+
list("ABCD"), ["float32", "float32", "float32", "float64"]
70+
)
71+
},
72+
index=Index([f"foo_{i}" for i in range(30)], dtype=object),
73+
)
74+
# not supported by numpy random
75+
df["C"] = df["C"].astype("float16")
10376
return df
10477

10578

@@ -109,32 +82,14 @@ def mixed_int_frame():
10982
Fixture for DataFrame of different int types with index of unique strings
11083
11184
Columns are ['A', 'B', 'C', 'D'].
112-
113-
A B C D
114-
mUrCZ67juP 0 1 2 2
115-
rw99ACYaKS 0 1 0 0
116-
7QsEcpaaVU 0 1 1 1
117-
xkrimI2pcE 0 1 0 0
118-
dz01SuzoS8 0 1 255 255
119-
ccQkqOHX75 -1 1 0 0
120-
DN0iXaoDLd 0 1 0 0
121-
... .. .. ... ...
122-
Dfb141wAaQ 1 1 254 254
123-
IPD8eQOVu5 0 1 0 0
124-
CcaKulsCmv 0 1 0 0
125-
rIBa8gu7E5 0 1 0 0
126-
RP6peZmh5o 0 1 1 1
127-
NMb9pipQWQ 0 1 0 0
128-
PqgbJEzjib 0 1 3 3
129-
130-
[30 rows x 4 columns]
13185
"""
132-
df = DataFrame({k: v.astype(int) for k, v in tm.getSeriesData().items()})
133-
df.A = df.A.astype("int32")
134-
df.B = np.ones(len(df.B), dtype="uint64")
135-
df.C = df.C.astype("uint8")
136-
df.D = df.C.astype("int64")
137-
return df
86+
return DataFrame(
87+
{
88+
col: np.ones(30, dtype=dtype)
89+
for col, dtype in zip(list("ABCD"), ["int32", "uint64", "uint8", "int64"])
90+
},
91+
index=Index([f"foo_{i}" for i in range(30)], dtype=object),
92+
)
13893

13994

14095
@pytest.fixture

pandas/tests/frame/methods/test_info.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,11 @@ def test_info_compute_numba():
532532

533533
with option_context("compute.use_numba", True):
534534
buf = StringIO()
535-
df.info()
535+
df.info(buf=buf)
536536
result = buf.getvalue()
537537

538538
buf = StringIO()
539-
df.info()
539+
df.info(buf=buf)
540540
expected = buf.getvalue()
541541
assert result == expected
542542

0 commit comments

Comments
 (0)