File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -468,6 +468,10 @@ def __mul__(self, other) -> Self:
468
468
if is_scalar (other ):
469
469
# numpy will accept float and int, raise TypeError for others
470
470
result = self ._ndarray * other
471
+ if result .dtype .kind != "m" :
472
+ # numpy >= 2.1 may not raise a TypeError
473
+ # and seems to dispatch to others.__rmul__?
474
+ raise TypeError (f"Cannot multiply with { type (other ).__name__ } " )
471
475
freq = None
472
476
if self .freq is not None and not isna (other ):
473
477
freq = self .freq * other
@@ -495,6 +499,10 @@ def __mul__(self, other) -> Self:
495
499
496
500
# numpy will accept float or int dtype, raise TypeError for others
497
501
result = self ._ndarray * other
502
+ if result .dtype .kind != "m" :
503
+ # numpy >= 2.1 may not raise a TypeError
504
+ # and seems to dispatch to others.__rmul__?
505
+ raise TypeError (f"Cannot multiply with { type (other ).__name__ } " )
498
506
return type (self )._simple_new (result , dtype = result .dtype )
499
507
500
508
__rmul__ = __mul__
Original file line number Diff line number Diff line change @@ -1454,7 +1454,13 @@ def test_td64arr_mul_int(self, box_with_array):
1454
1454
def test_td64arr_mul_tdlike_scalar_raises (self , two_hours , box_with_array ):
1455
1455
rng = timedelta_range ("1 days" , "10 days" , name = "foo" )
1456
1456
rng = tm .box_expected (rng , box_with_array )
1457
- msg = "argument must be an integer|cannot use operands with types dtype"
1457
+ msg = "|" .join (
1458
+ [
1459
+ "argument must be an integer" ,
1460
+ "cannot use operands with types dtype" ,
1461
+ "Cannot multiply with" ,
1462
+ ]
1463
+ )
1458
1464
with pytest .raises (TypeError , match = msg ):
1459
1465
rng * two_hours
1460
1466
You can’t perform that action at this time.
0 commit comments