@@ -200,6 +200,48 @@ def test_td_rsub_numeric_raises(self):
200
200
with pytest .raises (TypeError ):
201
201
2.0 - td
202
202
203
+ def test_td_sub_timedeltalike_object_dtype_array (self ):
204
+ # GH 21980
205
+ arr = np .array ([Timestamp ('20130101 9:01' ),
206
+ Timestamp ('20121230 9:02' )])
207
+ exp = np .array ([Timestamp ('20121231 9:01' ),
208
+ Timestamp ('20121229 9:02' )])
209
+ res = arr - pd .Timedelta ('1D' )
210
+ tm .assert_numpy_array_equal (res , exp )
211
+
212
+ def test_td_sub_mixed_most_timedeltalike_object_dtype_array (self ):
213
+ # GH 21980
214
+ now = pd .Timestamp .now ()
215
+ arr = np .array ([now ,
216
+ pd .Timedelta ('1D' ),
217
+ np .timedelta64 (2 , 'h' )])
218
+ exp = np .array ([now - pd .Timedelta ('1D' ),
219
+ pd .Timedelta ('0D' ),
220
+ np .timedelta64 (2 , 'h' ) - pd .Timedelta ('1D' )])
221
+ res = arr - pd .Timedelta ('1D' )
222
+ tm .assert_numpy_array_equal (res , exp )
223
+
224
+ @pytest .mark .parametrize ('op' , [operator .add , ops .radd ])
225
+ def test_td_add_timedeltalike_object_dtype_array (self , op ):
226
+ # GH 21980
227
+ arr = np .array ([Timestamp ('20130101 9:01' ),
228
+ Timestamp ('20121230 9:02' )])
229
+ exp = np .array ([Timestamp ('20130102 9:01' ),
230
+ Timestamp ('20121231 9:02' )])
231
+ res = op (arr , pd .Timedelta ('1D' ))
232
+ tm .assert_numpy_array_equal (res , exp )
233
+
234
+ @pytest .mark .parametrize ('op' , [operator .add , ops .radd ])
235
+ def test_td_add_mixed_timedeltalike_object_dtype_array (self , op ):
236
+ # GH 21980
237
+ now = pd .Timestamp .now ()
238
+ arr = np .array ([now ,
239
+ pd .Timedelta ('1D' )])
240
+ exp = np .array ([now + pd .Timedelta ('1D' ),
241
+ pd .Timedelta ('2D' )])
242
+ res = op (arr , pd .Timedelta ('1D' ))
243
+ tm .assert_numpy_array_equal (res , exp )
244
+
203
245
204
246
class TestTimedeltaMultiplicationDivision (object ):
205
247
"""
@@ -616,3 +658,17 @@ def test_rdivmod_invalid(self):
616
658
617
659
with pytest .raises (TypeError ):
618
660
divmod (np .array ([22 , 24 ]), td )
661
+
662
+ @pytest .mark .parametrize ('op' , [
663
+ operator .mul ,
664
+ ops .rmul ,
665
+ operator .truediv ,
666
+ ops .rdiv ,
667
+ ops .rsub ])
668
+ @pytest .mark .parametrize ('arr' , [
669
+ np .array ([Timestamp ('20130101 9:01' ), Timestamp ('20121230 9:02' )]),
670
+ np .array ([pd .Timestamp .now (), pd .Timedelta ('1D' )])
671
+ ])
672
+ def test_td_op_timedelta_timedeltalike_array (self , op , arr ):
673
+ with pytest .raises (TypeError ):
674
+ op (arr , pd .Timedelta ('1D' ))
0 commit comments