Skip to content
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

TST/CLN: Remove makeTime methods #56264

Merged
merged 6 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Remove makeTimeDataFrame
  • Loading branch information
mroeschke committed Nov 30, 2023
commit e3dc4116ffc9706e747d4808f29f660dac549a5e
7 changes: 0 additions & 7 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,6 @@ def getTimeSeriesData(nper=None, freq: Frequency = "B") -> dict[str, Series]:
return {c: makeTimeSeries(nper, freq) for c in getCols(_K)}


# make frame
def makeTimeDataFrame(nper=None, freq: Frequency = "B") -> DataFrame:
data = getTimeSeriesData(nper, freq)
return DataFrame(data)


def makeCustomIndex(
nentries,
nlevels,
Expand Down Expand Up @@ -901,7 +895,6 @@ def shares_memory(left, right) -> bool:
"loc",
"makeCustomDataframe",
"makeCustomIndex",
"makeTimeDataFrame",
"makeTimeSeries",
"maybe_produces_warning",
"NARROW_NP_DTYPES",
Expand Down
6 changes: 5 additions & 1 deletion pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,11 @@ def multiindex_year_month_day_dataframe_random_data():
DataFrame with 3 level MultiIndex (year, month, day) covering
first 100 business days from 2000-01-01 with random data
"""
tdf = tm.makeTimeDataFrame(100)
tdf = DataFrame(
np.random.default_rng(2).standard_normal((100, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=100, freq="B"),
)
ymd = tdf.groupby([lambda x: x.year, lambda x: x.month, lambda x: x.day]).sum()
# use int64 Index, to make sure things work
ymd.index = ymd.index.set_levels([lev.astype("i8") for lev in ymd.index.levels])
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ def test_fancy_getitem_slice_mixed(
tm.assert_frame_equal(float_frame, original)

def test_getitem_setitem_non_ix_labels(self):
df = tm.makeTimeDataFrame()
df = DataFrame(range(20), index=date_range("2020-01-01", periods=20))

start, end = df.index[[5, 10]]

Expand Down
10 changes: 8 additions & 2 deletions pandas/tests/frame/methods/test_cov_corr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import pandas as pd
from pandas import (
DataFrame,
Index,
Series,
date_range,
isna,
)
import pandas._testing as tm
Expand Down Expand Up @@ -325,8 +327,12 @@ def test_corrwith(self, datetime_frame, dtype):
tm.assert_almost_equal(correls[row], df1.loc[row].corr(df2.loc[row]))

def test_corrwith_with_objects(self):
df1 = tm.makeTimeDataFrame()
df2 = tm.makeTimeDataFrame()
df1 = DataFrame(
np.random.default_rng(2).standard_normal((10, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=10, freq="B"),
)
df2 = df1.copy()
cols = ["A", "B", "C", "D"]

df1["obj"] = "foo"
Expand Down
27 changes: 23 additions & 4 deletions pandas/tests/frame/methods/test_first_and_last.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""
Note: includes tests for `last`
"""
import numpy as np
import pytest

import pandas as pd
from pandas import (
DataFrame,
Index,
bdate_range,
date_range,
)
import pandas._testing as tm

Expand All @@ -16,13 +19,21 @@

class TestFirst:
def test_first_subset(self, frame_or_series):
ts = tm.makeTimeDataFrame(freq="12h")
ts = DataFrame(
np.random.default_rng(2).standard_normal((100, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=100, freq="12h"),
)
ts = tm.get_obj(ts, frame_or_series)
with tm.assert_produces_warning(FutureWarning, match=deprecated_msg):
result = ts.first("10d")
assert len(result) == 20

ts = tm.makeTimeDataFrame(freq="D")
ts = DataFrame(
np.random.default_rng(2).standard_normal((100, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=100, freq="D"),
)
ts = tm.get_obj(ts, frame_or_series)
with tm.assert_produces_warning(FutureWarning, match=deprecated_msg):
result = ts.first("10d")
Expand Down Expand Up @@ -64,13 +75,21 @@ def test_first_last_raises(self, frame_or_series):
obj.last("1D")

def test_last_subset(self, frame_or_series):
ts = tm.makeTimeDataFrame(freq="12h")
ts = DataFrame(
np.random.default_rng(2).standard_normal((100, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=100, freq="12h"),
)
ts = tm.get_obj(ts, frame_or_series)
with tm.assert_produces_warning(FutureWarning, match=last_deprecated_msg):
result = ts.last("10d")
assert len(result) == 20

ts = tm.makeTimeDataFrame(nper=30, freq="D")
ts = DataFrame(
np.random.default_rng(2).standard_normal((30, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=30, freq="D"),
)
ts = tm.get_obj(ts, frame_or_series)
with tm.assert_produces_warning(FutureWarning, match=last_deprecated_msg):
result = ts.last("10d")
Expand Down
8 changes: 6 additions & 2 deletions pandas/tests/frame/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1523,8 +1523,12 @@ def test_combineFunc(self, float_frame, mixed_float_frame):
[operator.eq, operator.ne, operator.lt, operator.gt, operator.ge, operator.le],
)
def test_comparisons(self, simple_frame, float_frame, func):
df1 = tm.makeTimeDataFrame()
df2 = tm.makeTimeDataFrame()
df1 = DataFrame(
np.random.default_rng(2).standard_normal((30, 4)),
columns=Index(list("ABCD"), dtype=object),
index=pd.date_range("2000-01-01", periods=30, freq="B"),
)
df2 = df1.copy()

row = simple_frame.xs("a")
ndim_5 = np.ones(df1.shape + (1, 1, 1))
Expand Down
48 changes: 39 additions & 9 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

from pandas import (
DataFrame,
Index,
Series,
date_range,
)
import pandas._testing as tm

Expand Down Expand Up @@ -328,12 +330,16 @@ def test_squeeze_series_noop(self, ser):

def test_squeeze_frame_noop(self):
# noop
df = tm.makeTimeDataFrame()
df = DataFrame(np.eye(2))
tm.assert_frame_equal(df.squeeze(), df)

def test_squeeze_frame_reindex(self):
# squeezing
df = tm.makeTimeDataFrame().reindex(columns=["A"])
df = DataFrame(
np.random.default_rng(2).standard_normal((10, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=10, freq="B"),
).reindex(columns=["A"])
tm.assert_series_equal(df.squeeze(), df["A"])

def test_squeeze_0_len_dim(self):
Expand All @@ -345,7 +351,11 @@ def test_squeeze_0_len_dim(self):

def test_squeeze_axis(self):
# axis argument
df = tm.makeTimeDataFrame(nper=1).iloc[:, :1]
df = DataFrame(
np.random.default_rng(2).standard_normal((1, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=1, freq="B"),
).iloc[:, :1]
assert df.shape == (1, 1)
tm.assert_series_equal(df.squeeze(axis=0), df.iloc[0])
tm.assert_series_equal(df.squeeze(axis="index"), df.iloc[0])
Expand All @@ -360,14 +370,22 @@ def test_squeeze_axis(self):
df.squeeze(axis="x")

def test_squeeze_axis_len_3(self):
df = tm.makeTimeDataFrame(3)
df = DataFrame(
np.random.default_rng(2).standard_normal((3, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=3, freq="B"),
)
tm.assert_frame_equal(df.squeeze(axis=0), df)

def test_numpy_squeeze(self):
s = Series(range(2), dtype=np.float64)
tm.assert_series_equal(np.squeeze(s), s)

df = tm.makeTimeDataFrame().reindex(columns=["A"])
df = DataFrame(
np.random.default_rng(2).standard_normal((10, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=10, freq="B"),
).reindex(columns=["A"])
tm.assert_series_equal(np.squeeze(df), df["A"])

@pytest.mark.parametrize(
Expand All @@ -382,11 +400,19 @@ def test_transpose_series(self, ser):
tm.assert_series_equal(ser.transpose(), ser)

def test_transpose_frame(self):
df = tm.makeTimeDataFrame()
df = DataFrame(
np.random.default_rng(2).standard_normal((10, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=10, freq="B"),
)
tm.assert_frame_equal(df.transpose().transpose(), df)

def test_numpy_transpose(self, frame_or_series):
obj = tm.makeTimeDataFrame()
obj = DataFrame(
np.random.default_rng(2).standard_normal((10, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=10, freq="B"),
)
obj = tm.get_obj(obj, frame_or_series)

if frame_or_series is Series:
Expand Down Expand Up @@ -419,7 +445,11 @@ def test_take_series(self, ser):

def test_take_frame(self):
indices = [1, 5, -2, 6, 3, -1]
df = tm.makeTimeDataFrame()
df = DataFrame(
np.random.default_rng(2).standard_normal((10, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=10, freq="B"),
)
out = df.take(indices)
expected = DataFrame(
data=df.values.take(indices, axis=0),
Expand All @@ -431,7 +461,7 @@ def test_take_frame(self):
def test_take_invalid_kwargs(self, frame_or_series):
indices = [-3, 2, 0, 1]

obj = tm.makeTimeDataFrame()
obj = DataFrame(range(5))
obj = tm.get_obj(obj, frame_or_series)

msg = r"take\(\) got an unexpected keyword argument 'foo'"
Expand Down
6 changes: 5 additions & 1 deletion pandas/tests/groupby/aggregate/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ def test_agg_apply_corner(ts, tsframe):


def test_agg_grouping_is_list_tuple(ts):
df = tm.makeTimeDataFrame()
df = DataFrame(
np.random.default_rng(2).standard_normal((30, 4)),
columns=Index(list("ABCD"), dtype=object),
index=pd.date_range("2000-01-01", periods=30, freq="B"),
)

grouped = df.groupby(lambda x: x.year)
grouper = grouped.grouper.groupings[0].grouping_vector
Expand Down
20 changes: 17 additions & 3 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,20 @@ def test_pass_args_kwargs_duplicate_columns(tsframe, as_index):


def test_len():
df = tm.makeTimeDataFrame()
df = DataFrame(
np.random.default_rng(2).standard_normal((10, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=10, freq="B"),
)
grouped = df.groupby([lambda x: x.year, lambda x: x.month, lambda x: x.day])
assert len(grouped) == len(df)

grouped = df.groupby([lambda x: x.year, lambda x: x.month])
expected = len({(x.year, x.month) for x in df.index})
assert len(grouped) == expected


def test_len_nan_group():
# issue 11016
df = DataFrame({"a": [np.nan] * 3, "b": [1, 2, 3]})
assert len(df.groupby("a")) == 0
Expand Down Expand Up @@ -940,7 +946,11 @@ def test_groupby_as_index_corner(df, ts):


def test_groupby_multiple_key():
df = tm.makeTimeDataFrame()
df = DataFrame(
np.random.default_rng(2).standard_normal((10, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=10, freq="B"),
)
grouped = df.groupby([lambda x: x.year, lambda x: x.month, lambda x: x.day])
agged = grouped.sum()
tm.assert_almost_equal(df.values, agged.values)
Expand Down Expand Up @@ -1655,7 +1665,11 @@ def test_dont_clobber_name_column():


def test_skip_group_keys():
tsf = tm.makeTimeDataFrame()
tsf = DataFrame(
np.random.default_rng(2).standard_normal((10, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=10, freq="B"),
)

grouped = tsf.groupby(lambda x: x.month, group_keys=False)
result = grouped.apply(lambda x: x.sort_values(by="A")[:3])
Expand Down
9 changes: 7 additions & 2 deletions pandas/tests/groupby/transform/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pandas import (
Categorical,
DataFrame,
Index,
MultiIndex,
Series,
Timestamp,
Expand Down Expand Up @@ -67,7 +68,11 @@ def demean(arr):
tm.assert_frame_equal(result, expected)

# GH 8430
df = tm.makeTimeDataFrame()
df = DataFrame(
np.random.default_rng(2).standard_normal((50, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=50, freq="B"),
)
g = df.groupby(pd.Grouper(freq="ME"))
g.transform(lambda x: x - 1)

Expand Down Expand Up @@ -115,7 +120,7 @@ def test_transform_fast2():
)
result = df.groupby("grouping").transform("first")

dates = pd.Index(
dates = Index(
[
Timestamp("2014-1-1"),
Timestamp("2014-1-2"),
Expand Down
15 changes: 12 additions & 3 deletions pandas/tests/indexes/multi/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import pandas as pd
from pandas import (
Categorical,
DataFrame,
Index,
MultiIndex,
date_range,
Expand All @@ -37,7 +38,11 @@ def test_slice_locs_partial(self, idx):
assert result == (2, 4)

def test_slice_locs(self):
df = tm.makeTimeDataFrame()
df = DataFrame(
np.random.default_rng(2).standard_normal((50, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=50, freq="B"),
)
stacked = df.stack(future_stack=True)
idx = stacked.index

Expand All @@ -57,7 +62,11 @@ def test_slice_locs(self):
tm.assert_almost_equal(sliced.values, expected.values)

def test_slice_locs_with_type_mismatch(self):
df = tm.makeTimeDataFrame()
df = DataFrame(
np.random.default_rng(2).standard_normal((10, 4)),
columns=Index(list("ABCD"), dtype=object),
index=date_range("2000-01-01", periods=10, freq="B"),
)
stacked = df.stack(future_stack=True)
idx = stacked.index
with pytest.raises(TypeError, match="^Level type mismatch"):
Expand Down Expand Up @@ -861,7 +870,7 @@ def test_timestamp_multiindex_indexer():
[3],
]
)
df = pd.DataFrame({"foo": np.arange(len(idx))}, idx)
df = DataFrame({"foo": np.arange(len(idx))}, idx)
result = df.loc[pd.IndexSlice["2019-1-2":, "x", :], "foo"]
qidx = MultiIndex.from_product(
[
Expand Down
Loading