@@ -200,6 +200,92 @@ 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_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
+ def test_td_rsub_timedeltalike_object_dtype_array (self ):
235
+ # GH 21980
236
+ arr = np .array ([Timestamp ('20130101 9:01' ),
237
+ Timestamp ('20121230 9:02' )])
238
+ with pytest .raises (TypeError ):
239
+ # an timedelta - timestamp doesnt make sense
240
+ pd .Timedelta ('1D' ) - arr
241
+
242
+ def test_td_rsub_mixed_timedeltalike_object_dtype_array (self ):
243
+ # GH 21980
244
+ now = pd .Timestamp .now ()
245
+ arr = np .array ([now ,
246
+ pd .Timedelta ('1D' )])
247
+ with pytest .raises (TypeError ):
248
+ # an timedelta - timestamp doesnt make sense
249
+ pd .Timedelta ('1D' ) - arr
250
+
251
+ def test_td_add_timedeltalike_object_dtype_array (self ):
252
+ # GH 21980
253
+ arr = np .array ([Timestamp ('20130101 9:01' ),
254
+ Timestamp ('20121230 9:02' )])
255
+ exp = np .array ([Timestamp ('20130102 9:01' ),
256
+ Timestamp ('20121231 9:02' )])
257
+ res = arr + pd .Timedelta ('1D' )
258
+ tm .assert_numpy_array_equal (res , exp )
259
+
260
+ def test_td_add_mixed_timedeltalike_object_dtype_array (self ):
261
+ # GH 21980
262
+ now = pd .Timestamp .now ()
263
+ arr = np .array ([now ,
264
+ pd .Timedelta ('1D' )])
265
+ exp = np .array ([now + pd .Timedelta ('1D' ),
266
+ pd .Timedelta ('2D' )])
267
+ res = arr + pd .Timedelta ('1D' )
268
+ tm .assert_numpy_array_equal (res , exp )
269
+
270
+ def test_td_radd_timedeltalike_object_dtype_array (self ):
271
+ # GH 21980
272
+ arr = np .array ([Timestamp ('20130101 9:01' ),
273
+ Timestamp ('20121230 9:02' )])
274
+ exp = np .array ([Timestamp ('20130102 9:01' ),
275
+ Timestamp ('20121231 9:02' )])
276
+ res = pd .Timedelta ('1D' ) + arr
277
+ tm .assert_numpy_array_equal (res , exp )
278
+
279
+ def test_td_radd_mixed_timedeltalike_object_dtype_array (self ):
280
+ # GH 21980
281
+ now = pd .Timestamp .now ()
282
+ arr = np .array ([now ,
283
+ pd .Timedelta ('1D' )])
284
+ exp = np .array ([now + pd .Timedelta ('1D' ),
285
+ pd .Timedelta ('2D' )])
286
+ res = pd .Timedelta ('1D' ) + arr
287
+ tm .assert_numpy_array_equal (res , exp )
288
+
203
289
204
290
class TestTimedeltaMultiplicationDivision (object ):
205
291
"""
@@ -616,3 +702,35 @@ def test_rdivmod_invalid(self):
616
702
617
703
with pytest .raises (TypeError ):
618
704
divmod (np .array ([22 , 24 ]), td )
705
+
706
+ def test_td_div_timedelta_timedeltalike_array (self ):
707
+ # GH 21980
708
+ arr = np .array ([Timestamp ('20130101 9:01' ),
709
+ Timestamp ('20121230 9:02' )])
710
+
711
+ with pytest .raises (TypeError ):
712
+ arr / pd .Timedelta ('1D' )
713
+
714
+ def test_td_rdiv_timedelta_mixed_timedeltalike_array (self ):
715
+ # GH 21980
716
+ arr = np .array ([pd .Timestamp .now (),
717
+ pd .Timedelta ('1D' )])
718
+
719
+ with pytest .raises (TypeError ):
720
+ pd .Timedelta ('1D' ) / arr
721
+
722
+ def test_td_mult_timedelta_mixed_timedeltalike_array (self ):
723
+ # GH 21980
724
+ arr = np .array ([pd .Timestamp .now (),
725
+ pd .Timedelta ('1D' )])
726
+
727
+ with pytest .raises (TypeError ):
728
+ pd .Timedelta ('1D' ) * arr
729
+
730
+ def test_td_rmult_timedelta_mixed_timedeltalike_array (self ):
731
+ # GH 21980
732
+ arr = np .array ([pd .Timestamp .now (),
733
+ pd .Timedelta ('1D' )])
734
+
735
+ with pytest .raises (TypeError ):
736
+ arr * pd .Timedelta ('1D' )
0 commit comments