@@ -200,6 +200,70 @@ def test_td_rsub_numeric_raises(self):
200200 with pytest .raises (TypeError ):
201201 2.0 - td
202202
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_timedeltalike_object_dtype_array (self ):
213+ # GH 21980
214+ now = pd .Timestamp .now ()
215+ arr = np .array ([now ,
216+ pd .Timedelta ('1D' )])
217+ exp = np .array ([now - pd .Timedelta ('1D' ),
218+ pd .Timedelta ('0D' )])
219+ res = arr - pd .Timedelta ('1D' )
220+ tm .assert_numpy_array_equal (res , exp )
221+
222+ def test_td_sub_mixed_most_timedeltalike_object_dtype_array (self ):
223+ # GH 21980
224+ now = pd .Timestamp .now ()
225+ arr = np .array ([now ,
226+ pd .Timedelta ('1D' ),
227+ np .timedelta64 (2 , 'h' )])
228+ exp = np .array ([now - pd .Timedelta ('1D' ),
229+ pd .Timedelta ('0D' ),
230+ np .timedelta64 (2 , 'h' ) - pd .Timedelta ('1D' )])
231+ res = arr - pd .Timedelta ('1D' )
232+ tm .assert_numpy_array_equal (res , exp )
233+
234+ @pytest .mark .parametrize ('arr' , [
235+ [Timestamp ('20130101 9:01' ),
236+ Timestamp ('20121230 9:02' )],
237+ [pd .Timestamp .now (),
238+ pd .Timedelta ('1D' )]
239+ ])
240+ def test_td_rsub_timedeltalike_object_dtype_array (self ,arr ):
241+ # GH 21980
242+ with pytest .raises (TypeError ):
243+ # an timedelta - timestamp doesnt make sense
244+ pd .Timedelta ('1D' ) - arr
245+
246+ @pytest .mark .parametrize ('op' , [operator .add , ops .radd ])
247+ def test_td_add_timedeltalike_object_dtype_array (self ,op ):
248+ # GH 21980
249+ arr = np .array ([Timestamp ('20130101 9:01' ),
250+ Timestamp ('20121230 9:02' )])
251+ exp = np .array ([Timestamp ('20130102 9:01' ),
252+ Timestamp ('20121231 9:02' )])
253+ res = op (arr , pd .Timedelta ('1D' ))
254+ tm .assert_numpy_array_equal (res , exp )
255+
256+ @pytest .mark .parametrize ('op' , [operator .add , ops .radd ])
257+ def test_td_add_mixed_timedeltalike_object_dtype_array (self ,op ):
258+ # GH 21980
259+ now = pd .Timestamp .now ()
260+ arr = np .array ([now ,
261+ pd .Timedelta ('1D' )])
262+ exp = np .array ([now + pd .Timedelta ('1D' ),
263+ pd .Timedelta ('2D' )])
264+ res = op (arr , pd .Timedelta ('1D' ))
265+ tm .assert_numpy_array_equal (res , exp )
266+
203267
204268class TestTimedeltaMultiplicationDivision (object ):
205269 """
@@ -616,3 +680,14 @@ def test_rdivmod_invalid(self):
616680
617681 with pytest .raises (TypeError ):
618682 divmod (np .array ([22 , 24 ]), td )
683+
684+ @pytest .mark .parametrize ('op' , [operator .mul , ops .rmul , operator .truediv , ops .rdiv ])
685+ @pytest .mark .parametrize ('arr' , [
686+ [Timestamp ('20130101 9:01' ),
687+ Timestamp ('20121230 9:02' )],
688+ [pd .Timestamp .now (),
689+ pd .Timedelta ('1D' )]
690+ ])
691+ def test_td_op_timedelta_timedeltalike_array (self , op , arr ):
692+ with pytest .raises (TypeError ):
693+ arr * pd .Timedelta ('1D' )
0 commit comments