Skip to content

Commit b5e1fc2

Browse files
jbrockmendeljreback
authored andcommitted
TST: bare-bones fixture for timedelta array tests (pandas-dev#23207)
1 parent 31f86d6 commit b5e1fc2

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

pandas/tests/arrays/test_datetimelike.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def datetime_index(request):
3434
A fixture to provide DatetimeIndex objects with different frequencies.
3535
3636
Most DatetimeArray behavior is already tested in DatetimeIndex tests,
37-
so here we just test that the DatetimeIndex behavior matches
37+
so here we just test that the DatetimeArray behavior matches
3838
the DatetimeIndex behavior.
3939
"""
4040
freqstr = request.param
@@ -45,6 +45,18 @@ def datetime_index(request):
4545
return pi
4646

4747

48+
@pytest.fixture
49+
def timedelta_index(request):
50+
"""
51+
A fixture to provide TimedeltaIndex objects with different frequencies.
52+
Most TimedeltaArray behavior is already tested in TimedeltaIndex tests,
53+
so here we just test that the TimedeltaArray behavior matches
54+
the TimedeltaIndex behavior.
55+
"""
56+
# TODO: flesh this out
57+
return pd.TimedeltaIndex(['1 Day', '3 Hours', 'NaT'])
58+
59+
4860
class TestDatetimeArray(object):
4961

5062
def test_from_dti(self, tz_naive_fixture):
@@ -122,6 +134,34 @@ def test_astype_object(self):
122134
assert asobj.dtype == 'O'
123135
assert list(asobj) == list(tdi)
124136

137+
def test_to_pytimedelta(self, timedelta_index):
138+
tdi = timedelta_index
139+
arr = TimedeltaArrayMixin(tdi)
140+
141+
expected = tdi.to_pytimedelta()
142+
result = arr.to_pytimedelta()
143+
144+
tm.assert_numpy_array_equal(result, expected)
145+
146+
def test_total_seconds(self, timedelta_index):
147+
tdi = timedelta_index
148+
arr = TimedeltaArrayMixin(tdi)
149+
150+
expected = tdi.total_seconds()
151+
result = arr.total_seconds()
152+
153+
tm.assert_numpy_array_equal(result, expected.values)
154+
155+
@pytest.mark.parametrize('propname', pd.TimedeltaIndex._field_ops)
156+
def test_int_properties(self, timedelta_index, propname):
157+
tdi = timedelta_index
158+
arr = TimedeltaArrayMixin(tdi)
159+
160+
result = getattr(arr, propname)
161+
expected = np.array(getattr(tdi, propname), dtype=result.dtype)
162+
163+
tm.assert_numpy_array_equal(result, expected)
164+
125165

126166
class TestPeriodArray(object):
127167

0 commit comments

Comments
 (0)