Skip to content

CLN/TST: Remove makeTimeSeries #56293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,11 @@
if TYPE_CHECKING:
from pandas._typing import (
Dtype,
Frequency,
NpDtype,
)

from pandas.core.arrays import ArrowExtensionArray

_N = 30

UNSIGNED_INT_NUMPY_DTYPES: list[NpDtype] = ["uint8", "uint16", "uint32", "uint64"]
UNSIGNED_INT_EA_DTYPES: list[Dtype] = ["UInt8", "UInt16", "UInt32", "UInt64"]
SIGNED_INT_NUMPY_DTYPES: list[NpDtype] = [int, "int8", "int16", "int32", "int64"]
Expand Down Expand Up @@ -339,16 +336,6 @@ def to_array(obj):
# Others


def makeTimeSeries(nper=None, freq: Frequency = "B", name=None) -> Series:
if nper is None:
nper = _N
return Series(
np.random.default_rng(2).standard_normal(nper),
index=date_range("2000-01-01", periods=nper, freq=freq),
name=name,
)


def makeCustomIndex(
nentries,
nlevels,
Expand Down Expand Up @@ -883,7 +870,6 @@ def shares_memory(left, right) -> bool:
"loc",
"makeCustomDataframe",
"makeCustomIndex",
"makeTimeSeries",
"maybe_produces_warning",
"NARROW_NP_DTYPES",
"NP_NAT_OBJECTS",
Expand Down
8 changes: 5 additions & 3 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,11 @@ def datetime_series() -> Series:
"""
Fixture for Series of floats with DatetimeIndex
"""
s = tm.makeTimeSeries()
s.name = "ts"
return s
return Series(
np.random.default_rng(2).standard_normal(30),
index=date_range("2000-01-01", periods=30, freq="B"),
name="ts",
)


def _create_series(index):
Expand Down
26 changes: 16 additions & 10 deletions pandas/tests/apply/test_series_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
MultiIndex,
Series,
concat,
date_range,
timedelta_range,
)
import pandas._testing as tm
Expand Down Expand Up @@ -134,7 +135,7 @@ def foo2(x, b=2, c=0):

def test_series_apply_map_box_timestamps(by_row):
# GH#2689, GH#2627
ser = Series(pd.date_range("1/1/2000", periods=10))
ser = Series(date_range("1/1/2000", periods=10))

def func(x):
return (x.hour, x.day, x.month)
Expand Down Expand Up @@ -194,13 +195,11 @@ def test_apply_box_period():


def test_apply_datetimetz(by_row):
values = pd.date_range("2011-01-01", "2011-01-02", freq="h").tz_localize(
"Asia/Tokyo"
)
values = date_range("2011-01-01", "2011-01-02", freq="h").tz_localize("Asia/Tokyo")
s = Series(values, name="XX")

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

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

Expand Down Expand Up @@ -510,8 +509,12 @@ def test_series_apply_no_suffix_index(by_row):
DataFrame(np.repeat([[1, 2]], 2, axis=0), dtype="int64"),
),
(
tm.makeTimeSeries(nper=30),
DataFrame(np.repeat([[1, 2]], 30, axis=0), dtype="int64"),
Series(
np.arange(10, dtype=np.float64),
index=date_range("2020-01-01", periods=10),
name="ts",
),
DataFrame(np.repeat([[1, 2]], 10, axis=0), dtype="int64"),
),
],
)
Expand All @@ -528,12 +531,15 @@ def test_apply_series_on_date_time_index_aware_series(dti, exp, aware):


@pytest.mark.parametrize(
"by_row, expected", [("compat", Series(np.ones(30), dtype="int64")), (False, 1)]
"by_row, expected", [("compat", Series(np.ones(10), dtype="int64")), (False, 1)]
)
def test_apply_scalar_on_date_time_index_aware_series(by_row, expected):
# GH 25959
# Calling apply on a localized time series should not cause an error
series = tm.makeTimeSeries(nper=30).tz_localize("UTC")
series = Series(
np.arange(10, dtype=np.float64),
index=date_range("2020-01-01", periods=10, tz="UTC"),
)
result = Series(series.index).apply(lambda x: 1, by_row=by_row)
tm.assert_equal(result, expected)

Expand Down
46 changes: 35 additions & 11 deletions pandas/tests/arithmetic/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Timedelta,
TimedeltaIndex,
array,
date_range,
)
import pandas._testing as tm
from pandas.core import ops
Expand Down Expand Up @@ -733,7 +734,7 @@ def test_mul_datelike_raises(self, numeric_idx):
idx = numeric_idx
msg = "cannot perform __rmul__ with this index type"
with pytest.raises(TypeError, match=msg):
idx * pd.date_range("20130101", periods=5)
idx * date_range("20130101", periods=5)

def test_mul_size_mismatch_raises(self, numeric_idx):
idx = numeric_idx
Expand Down Expand Up @@ -820,7 +821,11 @@ def test_ops_np_scalar(self, other):
# TODO: This came from series.test.test_operators, needs cleanup
def test_operators_frame(self):
# rpow does not work with DataFrame
ts = tm.makeTimeSeries()
ts = Series(
np.arange(10, dtype=np.float64),
index=date_range("2020-01-01", periods=10),
name="ts",
)
ts.name = "ts"

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

ts = tm.makeTimeSeries()
ts.name = "ts"
ts = Series(
np.arange(10, dtype=np.float64),
index=date_range("2020-01-01", periods=10),
name="ts",
)

# really raise this time
fix_now = fixed_now_ts.to_pydatetime()
Expand Down Expand Up @@ -955,8 +963,8 @@ def test_datetime64_with_index(self):
# GH#4629
# arithmetic datetime64 ops with an index
ser = Series(
pd.date_range("20130101", periods=5),
index=pd.date_range("20130101", periods=5),
date_range("20130101", periods=5),
index=date_range("20130101", periods=5),
)
expected = ser - ser.index.to_series()
result = ser - ser.index
Expand All @@ -969,7 +977,7 @@ def test_datetime64_with_index(self):

df = pd.DataFrame(
np.random.default_rng(2).standard_normal((5, 2)),
index=pd.date_range("20130101", periods=5),
index=date_range("20130101", periods=5),
)
df["date"] = pd.Timestamp("20130102")
df["expected"] = df["date"] - df.index.to_series()
Expand Down Expand Up @@ -1031,7 +1039,11 @@ def test_frame_operators_empty_like(self, dtype):
)
def test_series_operators_arithmetic(self, all_arithmetic_functions, func):
op = all_arithmetic_functions
series = tm.makeTimeSeries().rename("ts")
series = Series(
np.arange(10, dtype=np.float64),
index=date_range("2020-01-01", periods=10),
name="ts",
)
other = func(series)
compare_op(series, other, op)

Expand All @@ -1040,7 +1052,11 @@ def test_series_operators_arithmetic(self, all_arithmetic_functions, func):
)
def test_series_operators_compare(self, comparison_op, func):
op = comparison_op
series = tm.makeTimeSeries().rename("ts")
series = Series(
np.arange(10, dtype=np.float64),
index=date_range("2020-01-01", periods=10),
name="ts",
)
other = func(series)
compare_op(series, other, op)

Expand All @@ -1050,7 +1066,11 @@ def test_series_operators_compare(self, comparison_op, func):
ids=["multiply", "slice", "constant"],
)
def test_divmod(self, func):
series = tm.makeTimeSeries().rename("ts")
series = Series(
np.arange(10, dtype=np.float64),
index=date_range("2020-01-01", periods=10),
name="ts",
)
other = func(series)
results = divmod(series, other)
if isinstance(other, abc.Iterable) and len(series) != len(other):
Expand Down Expand Up @@ -1081,7 +1101,11 @@ def test_series_divmod_zero(self):
# -1/0 == -np.inf
# 1/-0.0 == -np.inf
# -1/-0.0 == np.inf
tser = tm.makeTimeSeries().rename("ts")
tser = Series(
np.arange(1, 11, dtype=np.float64),
index=date_range("2020-01-01", periods=10),
name="ts",
)
other = tser * 0

result = divmod(tser, other)
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/frame/methods/test_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,9 @@ def test_reindex_sparse(self):
tm.assert_frame_equal(result, expected)

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

newFrame = float_frame.reindex(datetime_series.index)

Expand Down
12 changes: 8 additions & 4 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,11 @@ def test_constructor_ordereddict(self):
assert expected == list(df.columns)

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

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

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

def test_constructor_dict_order_insertion(self):
datetime_series = tm.makeTimeSeries(nper=30)
datetime_series_short = tm.makeTimeSeries(nper=25)
datetime_series = Series(
np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
)
datetime_series_short = datetime_series[:5]

# GH19018
# initialization ordering: by insertion order if python>= 3.6
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/groupby/aggregate/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ def raiseException(df):


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

result = grouped.agg("sum")
Expand Down
7 changes: 5 additions & 2 deletions pandas/tests/groupby/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from pandas import (
DataFrame,
Index,
Series,
date_range,
)
import pandas._testing as tm
from pandas.core.groupby.base import (
reduction_kernels,
transformation_kernels,
Expand Down Expand Up @@ -47,7 +47,10 @@ def df():

@pytest.fixture
def ts():
return tm.makeTimeSeries()
return Series(
np.random.default_rng(2).standard_normal(30),
index=date_range("2000-01-01", periods=30, freq="B"),
)


@pytest.fixture
Expand Down
10 changes: 8 additions & 2 deletions pandas/tests/groupby/methods/test_describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
DataFrame,
Index,
MultiIndex,
Series,
Timestamp,
date_range,
)
import pandas._testing as tm

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


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


def test_series_describe_single():
ts = tm.makeTimeSeries()
ts = Series(
np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
)
grouped = ts.groupby(lambda x: x.month)
result = grouped.apply(lambda x: x.describe())
expected = grouped.describe().stack(future_stack=True)
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/io/formats/test_to_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,10 @@ def test_to_string_timedelta64(self):
assert result == "0 1 days\n1 2 days\n2 3 days"

def test_to_string(self):
ts = tm.makeTimeSeries()
ts = Series(
np.arange(10, dtype=np.float64),
index=date_range("2020-01-01", periods=10, freq="B"),
)
buf = StringIO()

s = ts.to_string()
Expand Down
7 changes: 5 additions & 2 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ def categorical_frame(self):
def datetime_series(self):
# Same as usual datetime_series, but with index freq set to None,
# since that doesn't round-trip, see GH#33711
ser = tm.makeTimeSeries()
ser.name = "ts"
ser = Series(
1.1 * np.arange(10, dtype=np.float64),
index=date_range("2020-01-01", periods=10),
name="ts",
)
ser.index = ser.index._with_freq(None)
return ser

Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/io/pytables/test_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ def test_append_series(setup_path):
with ensure_clean_store(setup_path) as store:
# basic
ss = Series(range(20), dtype=np.float64, index=[f"i_{i}" for i in range(20)])
ts = tm.makeTimeSeries()
ts = Series(
np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
)
ns = Series(np.arange(100))

store.append("ss", ss)
Expand Down
Loading