@@ -503,6 +503,8 @@ def __pow__(self: Array, other: Union[int, float, Array], /) -> Array:
503
503
504
504
if isinstance (other , (int , float , bool )):
505
505
other = self ._promote_scalar (other )
506
+ if self .dtype not in _floating_dtypes or other .dtype not in _floating_dtypes :
507
+ raise TypeError ('Only floating-point dtypes are allowed in __pow__' )
506
508
# Note: NumPy's __pow__ does not follow type promotion rules for 0-d
507
509
# arrays, so we use pow() here instead.
508
510
return pow (self , other )
@@ -548,6 +550,8 @@ def __truediv__(self: Array, other: Union[int, float, Array], /) -> Array:
548
550
"""
549
551
if isinstance (other , (int , float , bool )):
550
552
other = self ._promote_scalar (other )
553
+ if self .dtype not in _floating_dtypes or other .dtype not in _floating_dtypes :
554
+ raise TypeError ('Only floating-point dtypes are allowed in __truediv__' )
551
555
self , other = self ._normalize_two_args (self , other )
552
556
res = self ._array .__truediv__ (other ._array )
553
557
return self .__class__ ._new (res )
@@ -744,6 +748,8 @@ def __ipow__(self: Array, other: Union[int, float, Array], /) -> Array:
744
748
"""
745
749
if isinstance (other , (int , float , bool )):
746
750
other = self ._promote_scalar (other )
751
+ if self .dtype not in _floating_dtypes or other .dtype not in _floating_dtypes :
752
+ raise TypeError ('Only floating-point dtypes are allowed in __pow__' )
747
753
self ._array .__ipow__ (other ._array )
748
754
return self
749
755
@@ -756,6 +762,8 @@ def __rpow__(self: Array, other: Union[int, float, Array], /) -> Array:
756
762
757
763
if isinstance (other , (int , float , bool )):
758
764
other = self ._promote_scalar (other )
765
+ if self .dtype not in _floating_dtypes or other .dtype not in _floating_dtypes :
766
+ raise TypeError ('Only floating-point dtypes are allowed in __pow__' )
759
767
# Note: NumPy's __pow__ does not follow the spec type promotion rules
760
768
# for 0-d arrays, so we use pow() here instead.
761
769
return pow (other , self )
@@ -810,6 +818,8 @@ def __itruediv__(self: Array, other: Union[int, float, Array], /) -> Array:
810
818
"""
811
819
if isinstance (other , (int , float , bool )):
812
820
other = self ._promote_scalar (other )
821
+ if self .dtype not in _floating_dtypes or other .dtype not in _floating_dtypes :
822
+ raise TypeError ('Only floating-point dtypes are allowed in __truediv__' )
813
823
self ._array .__itruediv__ (other ._array )
814
824
return self
815
825
@@ -820,6 +830,8 @@ def __rtruediv__(self: Array, other: Union[int, float, Array], /) -> Array:
820
830
"""
821
831
if isinstance (other , (int , float , bool )):
822
832
other = self ._promote_scalar (other )
833
+ if self .dtype not in _floating_dtypes or other .dtype not in _floating_dtypes :
834
+ raise TypeError ('Only floating-point dtypes are allowed in __truediv__' )
823
835
self , other = self ._normalize_two_args (self , other )
824
836
res = self ._array .__rtruediv__ (other ._array )
825
837
return self .__class__ ._new (res )
0 commit comments