@@ -34,7 +34,7 @@ def datetime_index(request):
34
34
A fixture to provide DatetimeIndex objects with different frequencies.
35
35
36
36
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
38
38
the DatetimeIndex behavior.
39
39
"""
40
40
freqstr = request .param
@@ -45,6 +45,18 @@ def datetime_index(request):
45
45
return pi
46
46
47
47
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
+
48
60
class TestDatetimeArray (object ):
49
61
50
62
def test_from_dti (self , tz_naive_fixture ):
@@ -122,6 +134,34 @@ def test_astype_object(self):
122
134
assert asobj .dtype == 'O'
123
135
assert list (asobj ) == list (tdi )
124
136
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
+
125
165
126
166
class TestPeriodArray (object ):
127
167
0 commit comments