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