@@ -200,6 +200,80 @@ 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_timedelta_timedeltalike_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_timedelta_mixed_timedeltalike_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_rsub_timedelta_timedeltalike_array (self ):
223
+ # GH 21980
224
+ arr = np .array ([Timestamp ('20130101 9:01' ),
225
+ Timestamp ('20121230 9:02' )])
226
+ with pytest .raises (TypeError ):
227
+ # an timedelta - timestamp doesnt make sense
228
+ pd .Timedelta ('1D' ) - arr
229
+
230
+ def test_td_rsub_timedelta_mixed_timedeltalike_array (self ):
231
+ # GH 21980
232
+ now = pd .Timestamp .now ()
233
+ arr = np .array ([now ,
234
+ pd .Timedelta ('1D' )])
235
+ with pytest .raises (TypeError ):
236
+ # an timedelta - timestamp doesnt make sense
237
+ pd .Timedelta ('1D' ) - arr
238
+
239
+ def test_td_add_timedelta_timedeltalike_array (self ):
240
+ # GH 21980
241
+ arr = np .array ([Timestamp ('20130101 9:01' ),
242
+ Timestamp ('20121230 9:02' )])
243
+ exp = np .array ([Timestamp ('20130102 9:01' ),
244
+ Timestamp ('20121231 9:02' )])
245
+ res = arr + pd .Timedelta ('1D' )
246
+ tm .assert_numpy_array_equal (res , exp )
247
+
248
+ def test_td_add_timedelta_mixed_timedeltalike_array (self ):
249
+ # GH 21980
250
+ now = pd .Timestamp .now ()
251
+ arr = np .array ([now ,
252
+ pd .Timedelta ('1D' )])
253
+ exp = np .array ([now + pd .Timedelta ('1D' ),
254
+ pd .Timedelta ('2D' )])
255
+ res = arr + pd .Timedelta ('1D' )
256
+ tm .assert_numpy_array_equal (res , exp )
257
+
258
+ def test_td_radd_timedelta_timedeltalike_array (self ):
259
+ # GH 21980
260
+ arr = np .array ([Timestamp ('20130101 9:01' ),
261
+ Timestamp ('20121230 9:02' )])
262
+ exp = np .array ([Timestamp ('20130102 9:01' ),
263
+ Timestamp ('20121231 9:02' )])
264
+ res = pd .Timedelta ('1D' ) + arr
265
+ tm .assert_numpy_array_equal (res , exp )
266
+
267
+ def test_td_radd_timedelta_mixed_timedeltalike_array (self ):
268
+ # GH 21980
269
+ now = pd .Timestamp .now ()
270
+ arr = np .array ([now ,
271
+ pd .Timedelta ('1D' )])
272
+ exp = np .array ([now + pd .Timedelta ('1D' ),
273
+ pd .Timedelta ('2D' )])
274
+ res = pd .Timedelta ('1D' ) + arr
275
+ tm .assert_numpy_array_equal (res , exp )
276
+
203
277
204
278
class TestTimedeltaMultiplicationDivision (object ):
205
279
"""
@@ -616,3 +690,35 @@ def test_rdivmod_invalid(self):
616
690
617
691
with pytest .raises (TypeError ):
618
692
divmod (np .array ([22 , 24 ]), td )
693
+
694
+ def test_td_div_timedelta_timedeltalike_array (self ):
695
+ # GH 21980
696
+ arr = np .array ([Timestamp ('20130101 9:01' ),
697
+ Timestamp ('20121230 9:02' )])
698
+
699
+ with pytest .raises (TypeError ):
700
+ arr / pd .Timedelta ('1D' )
701
+
702
+ def test_td_rdiv_timedelta_mixed_timedeltalike_array (self ):
703
+ # GH 21980
704
+ arr = np .array ([pd .Timestamp .now (),
705
+ pd .Timedelta ('1D' )])
706
+
707
+ with pytest .raises (TypeError ):
708
+ pd .Timedelta ('1D' ) / arr
709
+
710
+ def test_td_mult_timedelta_mixed_timedeltalike_array (self ):
711
+ # GH 21980
712
+ arr = np .array ([pd .Timestamp .now (),
713
+ pd .Timedelta ('1D' )])
714
+
715
+ with pytest .raises (TypeError ):
716
+ pd .Timedelta ('1D' ) * arr
717
+
718
+ def test_td_rmult_timedelta_mixed_timedeltalike_array (self ):
719
+ # GH 21980
720
+ arr = np .array ([pd .Timestamp .now (),
721
+ pd .Timedelta ('1D' )])
722
+
723
+ with pytest .raises (TypeError ):
724
+ arr * pd .Timedelta ('1D' )
0 commit comments