@@ -471,6 +471,10 @@ def __mul__(self, other):
471
471
if not hasattr (other , "dtype" ):
472
472
# list, tuple
473
473
other = np .array (other )
474
+ if len (other ) != len (self ) and not is_timedelta64_dtype (other .dtype ):
475
+ # Exclude timedelta64 here so we correctly raise TypeError
476
+ # for that instead of ValueError
477
+ raise ValueError ("Cannot multiply with unequal lengths" )
474
478
475
479
if is_object_dtype (other .dtype ):
476
480
# this multiplication will succeed only if all elements of other
@@ -514,7 +518,10 @@ def __truediv__(self, other):
514
518
# e.g. list, tuple
515
519
other = np .array (other )
516
520
517
- if is_timedelta64_dtype (other .dtype ):
521
+ if len (other ) != len (self ):
522
+ raise ValueError ("Cannot divide vectors with unequal lengths" )
523
+
524
+ elif is_timedelta64_dtype (other .dtype ):
518
525
# let numpy handle it
519
526
return self ._data / other
520
527
@@ -564,7 +571,10 @@ def __rtruediv__(self, other):
564
571
# e.g. list, tuple
565
572
other = np .array (other )
566
573
567
- if is_timedelta64_dtype (other .dtype ):
574
+ if len (other ) != len (self ):
575
+ raise ValueError ("Cannot divide vectors with unequal lengths" )
576
+
577
+ elif is_timedelta64_dtype (other .dtype ):
568
578
# let numpy handle it
569
579
return other / self ._data
570
580
@@ -613,8 +623,10 @@ def __floordiv__(self, other):
613
623
if not hasattr (other , "dtype" ):
614
624
# list, tuple
615
625
other = np .array (other )
626
+ if len (other ) != len (self ):
627
+ raise ValueError ("Cannot divide with unequal lengths" )
616
628
617
- if is_timedelta64_dtype (other .dtype ):
629
+ elif is_timedelta64_dtype (other .dtype ):
618
630
other = type (self )(other )
619
631
620
632
# numpy timedelta64 does not natively support floordiv, so operate
@@ -666,7 +678,10 @@ def __rfloordiv__(self, other):
666
678
# list, tuple
667
679
other = np .array (other )
668
680
669
- if is_timedelta64_dtype (other .dtype ):
681
+ if len (other ) != len (self ):
682
+ raise ValueError ("Cannot divide with unequal lengths" )
683
+
684
+ elif is_timedelta64_dtype (other .dtype ):
670
685
other = type (self )(other )
671
686
672
687
# numpy timedelta64 does not natively support floordiv, so operate
0 commit comments