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 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
19 changes: 0 additions & 19 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import operator
import os
import re
import string
from sys import byteorder
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -109,7 +108,6 @@
from pandas.core.arrays import ArrowExtensionArray

_N = 30
_K = 4

UNSIGNED_INT_NUMPY_DTYPES: list[NpDtype] = ["uint8", "uint16", "uint32", "uint64"]
UNSIGNED_INT_EA_DTYPES: list[Dtype] = ["UInt8", "UInt16", "UInt32", "UInt64"]
Expand Down Expand Up @@ -341,10 +339,6 @@ def to_array(obj):
# Others


def getCols(k) -> str:
return string.ascii_uppercase[:k]


def makeTimeSeries(nper=None, freq: Frequency = "B", name=None) -> Series:
if nper is None:
nper = _N
Expand All @@ -355,16 +349,6 @@ def makeTimeSeries(nper=None, freq: Frequency = "B", name=None) -> Series:
)


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 @@ -887,21 +871,18 @@ def shares_memory(left, right) -> bool:
"external_error_raised",
"FLOAT_EA_DTYPES",
"FLOAT_NUMPY_DTYPES",
"getCols",
"get_cython_table_params",
"get_dtype",
"getitem",
"get_locales",
"get_finest_unit",
"get_obj",
"get_op_from_name",
"getTimeSeriesData",
"iat",
"iloc",
"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
26 changes: 5 additions & 21 deletions pandas/tests/frame/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
NaT,
date_range,
)
import pandas._testing as tm


@pytest.fixture
Expand All @@ -16,27 +15,12 @@ def datetime_frame() -> DataFrame:
Fixture for DataFrame of floats with DatetimeIndex

Columns are ['A', 'B', 'C', 'D']

A B C D
2000-01-03 -1.122153 0.468535 0.122226 1.693711
2000-01-04 0.189378 0.486100 0.007864 -1.216052
2000-01-05 0.041401 -0.835752 -0.035279 -0.414357
2000-01-06 0.430050 0.894352 0.090719 0.036939
2000-01-07 -0.620982 -0.668211 -0.706153 1.466335
2000-01-10 -0.752633 0.328434 -0.815325 0.699674
2000-01-11 -2.236969 0.615737 -0.829076 -1.196106
... ... ... ... ...
2000-02-03 1.642618 -0.579288 0.046005 1.385249
2000-02-04 -0.544873 -1.160962 -0.284071 -1.418351
2000-02-07 -2.656149 -0.601387 1.410148 0.444150
2000-02-08 -1.201881 -1.289040 0.772992 -1.445300
2000-02-09 1.377373 0.398619 1.008453 -0.928207
2000-02-10 0.473194 -0.636677 0.984058 0.511519
2000-02-11 -0.965556 0.408313 -1.312844 -0.381948

[30 rows x 4 columns]
"""
return DataFrame(tm.getTimeSeriesData())
return 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"),
)


@pytest.fixture
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
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_truncate.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_truncate(self, datetime_frame, frame_or_series):
truncated = ts.truncate(before=ts.index[-1] + ts.index.freq)
assert len(truncated) == 0

msg = "Truncate: 2000-01-06 00:00:00 must be after 2000-02-04 00:00:00"
msg = "Truncate: 2000-01-06 00:00:00 must be after 2000-05-16 00:00:00"
with pytest.raises(ValueError, match=msg):
ts.truncate(
before=ts.index[-1] - ts.index.freq, after=ts.index[0] + ts.index.freq
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
12 changes: 10 additions & 2 deletions pandas/tests/groupby/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import numpy as np
import pytest

from pandas import DataFrame
from pandas import (
DataFrame,
Index,
date_range,
)
import pandas._testing as tm
from pandas.core.groupby.base import (
reduction_kernels,
Expand Down Expand Up @@ -48,7 +52,11 @@ def ts():

@pytest.fixture
def tsframe():
return DataFrame(tm.getTimeSeriesData())
return 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="B"),
)


@pytest.fixture
Expand Down
Loading
Loading