@@ -442,39 +442,36 @@ def test_tdi_floordiv_timedelta_scalar(self, scalar_td):
442
442
res = tdi // (scalar_td )
443
443
tm .assert_index_equal (res , expected )
444
444
445
- # TODO: Split by operation, better name
446
- def test_ops_compat (self ):
445
+ def test_tdi_floordiv_tdlike_scalar (self , delta ):
446
+ tdi = timedelta_range ('1 days' , '10 days' , name = 'foo' )
447
+ expected = Int64Index ((np .arange (10 ) + 1 ) * 12 , name = 'foo' )
447
448
448
- offsets = [ pd . offsets . Hour ( 2 ), timedelta ( hours = 2 ),
449
- np . timedelta64 ( 2 , 'h' ), Timedelta ( hours = 2 )]
449
+ result = tdi // delta
450
+ tm . assert_index_equal ( result , expected , exact = False )
450
451
452
+ def test_tdi_mul_tdlike_scalar_raises (self , delta ):
451
453
rng = timedelta_range ('1 days' , '10 days' , name = 'foo' )
454
+ with pytest .raises (TypeError ):
455
+ rng * delta
452
456
453
- # multiply
454
- for offset in offsets :
455
- pytest .raises (TypeError , lambda : rng * offset )
457
+ def test_tdi_div_nat_raises (self ):
458
+ # don't allow division by NaT (make could in the future)
459
+ rng = timedelta_range ('1 days' , '10 days' , name = 'foo' )
460
+ with pytest .raises (TypeError ):
461
+ rng / pd .NaT
456
462
457
- # divide
463
+ def test_tdi_div_tdlike_scalar (self , delta ):
464
+ rng = timedelta_range ('1 days' , '10 days' , name = 'foo' )
458
465
expected = Int64Index ((np .arange (10 ) + 1 ) * 12 , name = 'foo' )
459
- for offset in offsets :
460
- result = rng / offset
461
- tm .assert_index_equal (result , expected , exact = False )
462
466
463
- # floor divide
464
- expected = Int64Index ((np .arange (10 ) + 1 ) * 12 , name = 'foo' )
465
- for offset in offsets :
466
- result = rng // offset
467
- tm .assert_index_equal (result , expected , exact = False )
467
+ result = rng / delta
468
+ tm .assert_index_equal (result , expected , exact = False )
468
469
469
- # divide with nats
470
+ def test_tdi_div_tdlike_scalar_with_nat ( self , delta ):
470
471
rng = TimedeltaIndex (['1 days' , pd .NaT , '2 days' ], name = 'foo' )
471
472
expected = Float64Index ([12 , np .nan , 24 ], name = 'foo' )
472
- for offset in offsets :
473
- result = rng / offset
474
- tm .assert_index_equal (result , expected )
475
-
476
- # don't allow division by NaT (make could in the future)
477
- pytest .raises (TypeError , lambda : rng / pd .NaT )
473
+ result = rng / delta
474
+ tm .assert_index_equal (result , expected )
478
475
479
476
def test_subtraction_ops (self ):
480
477
# with datetimes/timedelta and tdi/dti
0 commit comments