Skip to content

Commit 09fb8e5

Browse files
authored
TST/CLN: Remove make_rand_series (#56163)
* TST/CLN: Remove make_rand_series * Remove old usages * Adjust test
1 parent 20ce643 commit 09fb8e5

File tree

16 files changed

+59
-59
lines changed

16 files changed

+59
-59
lines changed

pandas/_testing/__init__.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -456,23 +456,6 @@ def makePeriodIndex(k: int = 10, name=None, **kwargs) -> PeriodIndex:
456456
return pi
457457

458458

459-
# make series
460-
def make_rand_series(name=None, dtype=np.float64) -> Series:
461-
index = makeStringIndex(_N)
462-
data = np.random.default_rng(2).standard_normal(_N)
463-
with np.errstate(invalid="ignore"):
464-
data = data.astype(dtype, copy=False)
465-
return Series(data, index=index, name=name)
466-
467-
468-
def makeFloatSeries(name=None) -> Series:
469-
return make_rand_series(name=name)
470-
471-
472-
def makeStringSeries(name=None) -> Series:
473-
return make_rand_series(name=name)
474-
475-
476459
def makeObjectSeries(name=None) -> Series:
477460
data = makeStringIndex(_N)
478461
data = Index(data, dtype=object)
@@ -1073,16 +1056,13 @@ def shares_memory(left, right) -> bool:
10731056
"makeDataFrame",
10741057
"makeDateIndex",
10751058
"makeFloatIndex",
1076-
"makeFloatSeries",
10771059
"makeIntIndex",
10781060
"makeMixedDataFrame",
10791061
"makeNumericIndex",
10801062
"makeObjectSeries",
10811063
"makePeriodIndex",
1082-
"make_rand_series",
10831064
"makeRangeIndex",
10841065
"makeStringIndex",
1085-
"makeStringSeries",
10861066
"makeTimeDataFrame",
10871067
"makeTimedeltaIndex",
10881068
"makeTimeSeries",

pandas/conftest.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,9 +729,11 @@ def string_series() -> Series:
729729
"""
730730
Fixture for Series of floats with Index of unique strings
731731
"""
732-
s = tm.makeStringSeries()
733-
s.name = "series"
734-
return s
732+
return Series(
733+
np.arange(30, dtype=np.float64) * 1.1,
734+
index=Index([f"i_{i}" for i in range(30)], dtype=object),
735+
name="series",
736+
)
735737

736738

737739
@pytest.fixture
@@ -776,7 +778,9 @@ def series_with_simple_index(index) -> Series:
776778

777779

778780
_narrow_series = {
779-
f"{dtype.__name__}-series": tm.make_rand_series(name="a", dtype=dtype)
781+
f"{dtype.__name__}-series": Series(
782+
range(30), index=[f"i-{i}" for i in range(30)], name="a", dtype=dtype
783+
)
780784
for dtype in tm.NARROW_NP_DTYPES
781785
}
782786

pandas/tests/apply/test_invalid_arg.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,8 @@ def test_transform_wont_agg_series(string_series, func):
338338
# we are trying to transform with an aggregator
339339
msg = "Function did not transform"
340340

341-
warn = RuntimeWarning if func[0] == "sqrt" else None
342-
warn_msg = "invalid value encountered in sqrt"
343341
with pytest.raises(ValueError, match=msg):
344-
with tm.assert_produces_warning(warn, match=warn_msg, check_stacklevel=False):
345-
string_series.transform(func)
342+
string_series.transform(func)
346343

347344

348345
@pytest.mark.parametrize(

pandas/tests/base/test_misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def test_memory_usage_components_series(series_with_simple_index):
132132

133133
@pytest.mark.parametrize("dtype", tm.NARROW_NP_DTYPES)
134134
def test_memory_usage_components_narrow_series(dtype):
135-
series = tm.make_rand_series(name="a", dtype=dtype)
135+
series = Series(range(5), dtype=dtype, index=[f"i-{i}" for i in range(5)], name="a")
136136
total_usage = series.memory_usage(index=True)
137137
non_index_usage = series.memory_usage(index=False)
138138
index_usage = series.index.memory_usage()

pandas/tests/dtypes/test_missing.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ def test_notna_notnull(notna_f):
7878
@pytest.mark.parametrize(
7979
"ser",
8080
[
81-
tm.makeFloatSeries(),
82-
tm.makeStringSeries(),
8381
tm.makeObjectSeries(),
8482
tm.makeTimeSeries(),
8583
Series(range(5), period_range("2020-01-01", periods=5)),

pandas/tests/generic/test_generic.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,11 @@ class TestNDFrame:
316316
# tests that don't fit elsewhere
317317

318318
@pytest.mark.parametrize(
319-
"ser", [tm.makeFloatSeries(), tm.makeStringSeries(), tm.makeObjectSeries()]
319+
"ser",
320+
[
321+
Series(range(10), dtype=np.float64),
322+
Series([str(i) for i in range(10)], dtype=object),
323+
],
320324
)
321325
def test_squeeze_series_noop(self, ser):
322326
# noop
@@ -360,14 +364,18 @@ def test_squeeze_axis_len_3(self):
360364
tm.assert_frame_equal(df.squeeze(axis=0), df)
361365

362366
def test_numpy_squeeze(self):
363-
s = tm.makeFloatSeries()
367+
s = Series(range(2), dtype=np.float64)
364368
tm.assert_series_equal(np.squeeze(s), s)
365369

366370
df = tm.makeTimeDataFrame().reindex(columns=["A"])
367371
tm.assert_series_equal(np.squeeze(df), df["A"])
368372

369373
@pytest.mark.parametrize(
370-
"ser", [tm.makeFloatSeries(), tm.makeStringSeries(), tm.makeObjectSeries()]
374+
"ser",
375+
[
376+
Series(range(10), dtype=np.float64),
377+
Series([str(i) for i in range(10)], dtype=object),
378+
],
371379
)
372380
def test_transpose_series(self, ser):
373381
# calls implementation in pandas/core/base.py
@@ -393,7 +401,11 @@ def test_numpy_transpose(self, frame_or_series):
393401
np.transpose(obj, axes=1)
394402

395403
@pytest.mark.parametrize(
396-
"ser", [tm.makeFloatSeries(), tm.makeStringSeries(), tm.makeObjectSeries()]
404+
"ser",
405+
[
406+
Series(range(10), dtype=np.float64),
407+
Series([str(i) for i in range(10)], dtype=object),
408+
],
397409
)
398410
def test_take_series(self, ser):
399411
indices = [1, 5, -2, 6, 3, -1]

pandas/tests/io/pytables/test_append.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_append(setup_path):
9999
def test_append_series(setup_path):
100100
with ensure_clean_store(setup_path) as store:
101101
# basic
102-
ss = tm.makeStringSeries()
102+
ss = Series(range(20), dtype=np.float64, index=[f"i_{i}" for i in range(20)])
103103
ts = tm.makeTimeSeries()
104104
ns = Series(np.arange(100))
105105

pandas/tests/io/pytables/test_keys.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pandas import (
44
DataFrame,
55
HDFStore,
6+
Series,
67
_testing as tm,
78
)
89
from pandas.tests.io.pytables.common import (
@@ -16,7 +17,9 @@
1617
def test_keys(setup_path):
1718
with ensure_clean_store(setup_path) as store:
1819
store["a"] = tm.makeTimeSeries()
19-
store["b"] = tm.makeStringSeries()
20+
store["b"] = Series(
21+
range(10), dtype="float64", index=[f"i_{i}" for i in range(10)]
22+
)
2023
store["c"] = tm.makeDataFrame()
2124

2225
assert len(store) == 3

pandas/tests/io/pytables/test_read.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def test_read_hdf_series_mode_r(tmp_path, format, setup_path):
356356
# GH 16583
357357
# Tests that reading a Series saved to an HDF file
358358
# still works if a mode='r' argument is supplied
359-
series = tm.makeFloatSeries()
359+
series = Series(range(10), dtype=np.float64)
360360
path = tmp_path / setup_path
361361
series.to_hdf(path, key="data", format=format)
362362
result = read_hdf(path, key="data", mode="r")

pandas/tests/io/pytables/test_round_trip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def roundtrip(key, obj, **kwargs):
3636
o = tm.makeTimeSeries()
3737
tm.assert_series_equal(o, roundtrip("series", o))
3838

39-
o = tm.makeStringSeries()
39+
o = Series(range(10), dtype="float64", index=[f"i_{i}" for i in range(10)])
4040
tm.assert_series_equal(o, roundtrip("string_series", o))
4141

4242
o = tm.makeDataFrame()
@@ -249,7 +249,7 @@ def test_table_values_dtypes_roundtrip(setup_path):
249249

250250
@pytest.mark.filterwarnings("ignore::pandas.errors.PerformanceWarning")
251251
def test_series(setup_path):
252-
s = tm.makeStringSeries()
252+
s = Series(range(10), dtype="float64", index=[f"i_{i}" for i in range(10)])
253253
_check_roundtrip(s, tm.assert_series_equal, path=setup_path)
254254

255255
ts = tm.makeTimeSeries()

0 commit comments

Comments
 (0)