Skip to content

Commit 7ce722c

Browse files
jbrockmendeljreback
authored andcommitted
TST: Collect/Use arithmetic test fixtures (#22645)
1 parent a959ca2 commit 7ce722c

File tree

5 files changed

+279
-365
lines changed

5 files changed

+279
-365
lines changed

pandas/tests/arithmetic/conftest.py

+98-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,32 @@ def zero(request):
2828
return request.param
2929

3030

31+
# ------------------------------------------------------------------
32+
# Vector Fixtures
33+
3134
@pytest.fixture(params=[pd.Float64Index(np.arange(5, dtype='float64')),
3235
pd.Int64Index(np.arange(5, dtype='int64')),
33-
pd.UInt64Index(np.arange(5, dtype='uint64'))],
36+
pd.UInt64Index(np.arange(5, dtype='uint64')),
37+
pd.RangeIndex(5)],
3438
ids=lambda x: type(x).__name__)
35-
def idx(request):
39+
def numeric_idx(request):
40+
"""
41+
Several types of numeric-dtypes Index objects
42+
"""
3643
return request.param
3744

3845

46+
@pytest.fixture
47+
def tdser():
48+
"""
49+
Return a Series with dtype='timedelta64[ns]', including a NaT.
50+
"""
51+
return pd.Series(['59 Days', '59 Days', 'NaT'], dtype='timedelta64[ns]')
52+
53+
54+
# ------------------------------------------------------------------
55+
# Scalar Fixtures
56+
3957
@pytest.fixture(params=[pd.Timedelta('5m4s').to_pytimedelta(),
4058
pd.Timedelta('5m4s'),
4159
pd.Timedelta('5m4s').to_timedelta64()],
@@ -47,6 +65,72 @@ def scalar_td(request):
4765
return request.param
4866

4967

68+
@pytest.fixture(params=[pd.offsets.Day(3),
69+
pd.offsets.Hour(72),
70+
pd.Timedelta(days=3).to_pytimedelta(),
71+
pd.Timedelta('72:00:00'),
72+
np.timedelta64(3, 'D'),
73+
np.timedelta64(72, 'h')])
74+
def three_days(request):
75+
"""
76+
Several timedelta-like and DateOffset objects that each represent
77+
a 3-day timedelta
78+
"""
79+
return request.param
80+
81+
82+
@pytest.fixture(params=[pd.offsets.Hour(2),
83+
pd.offsets.Minute(120),
84+
pd.Timedelta(hours=2).to_pytimedelta(),
85+
pd.Timedelta(seconds=2 * 3600),
86+
np.timedelta64(2, 'h'),
87+
np.timedelta64(120, 'm')])
88+
def two_hours(request):
89+
"""
90+
Several timedelta-like and DateOffset objects that each represent
91+
a 2-hour timedelta
92+
"""
93+
return request.param
94+
95+
96+
_common_mismatch = [pd.offsets.YearBegin(2),
97+
pd.offsets.MonthBegin(1),
98+
pd.offsets.Minute()]
99+
100+
101+
@pytest.fixture(params=[pd.Timedelta(minutes=30).to_pytimedelta(),
102+
np.timedelta64(30, 's'),
103+
pd.Timedelta(seconds=30)] + _common_mismatch)
104+
def not_hourly(request):
105+
"""
106+
Several timedelta-like and DateOffset instances that are _not_
107+
compatible with Hourly frequencies.
108+
"""
109+
return request.param
110+
111+
112+
@pytest.fixture(params=[np.timedelta64(4, 'h'),
113+
pd.Timedelta(hours=23).to_pytimedelta(),
114+
pd.Timedelta('23:00:00')] + _common_mismatch)
115+
def not_daily(request):
116+
"""
117+
Several timedelta-like and DateOffset instances that are _not_
118+
compatible with Daily frequencies.
119+
"""
120+
return request.param
121+
122+
123+
@pytest.fixture(params=[np.timedelta64(365, 'D'),
124+
pd.Timedelta(days=365).to_pytimedelta(),
125+
pd.Timedelta(days=365)] + _common_mismatch)
126+
def mismatched_freq(request):
127+
"""
128+
Several timedelta-like and DateOffset instances that are _not_
129+
compatible with Monthly or Annual frequencies.
130+
"""
131+
return request.param
132+
133+
50134
# ------------------------------------------------------------------
51135

52136
@pytest.fixture(params=[pd.Index, pd.Series, pd.DataFrame],
@@ -59,6 +143,18 @@ def box(request):
59143
return request.param
60144

61145

146+
@pytest.fixture(params=[pd.Index,
147+
pd.Series,
148+
pytest.param(pd.DataFrame,
149+
marks=pytest.mark.xfail(strict=True))],
150+
ids=lambda x: x.__name__)
151+
def box_df_fail(request):
152+
"""
153+
Fixture equivalent to `box` fixture but xfailing the DataFrame case.
154+
"""
155+
return request.param
156+
157+
62158
@pytest.fixture(params=[
63159
pd.Index,
64160
pd.Series,

0 commit comments

Comments
 (0)