@@ -848,7 +848,11 @@ def add(
848
848
xp : ModuleType | None = None ,
849
849
) -> Array : # numpydoc ignore=PR01,RT01
850
850
"""Apply ``x[idx] += y`` and return the updated array."""
851
- return self ._iop ("add" , operator .add , y , copy = copy , xp = xp )
851
+
852
+ # Note for this and all other methods based on _iop:
853
+ # operator.iadd and operator.add subtly differ in behaviour, as
854
+ # only iadd will trigger exceptions when y has an incompatible dtype.
855
+ return self ._iop ("add" , operator .iadd , y , copy = copy , xp = xp )
852
856
853
857
def subtract (
854
858
self ,
@@ -858,7 +862,7 @@ def subtract(
858
862
xp : ModuleType | None = None ,
859
863
) -> Array : # numpydoc ignore=PR01,RT01
860
864
"""Apply ``x[idx] -= y`` and return the updated array."""
861
- return self ._iop ("subtract" , operator .sub , y , copy = copy , xp = xp )
865
+ return self ._iop ("subtract" , operator .isub , y , copy = copy , xp = xp )
862
866
863
867
def multiply (
864
868
self ,
@@ -868,7 +872,7 @@ def multiply(
868
872
xp : ModuleType | None = None ,
869
873
) -> Array : # numpydoc ignore=PR01,RT01
870
874
"""Apply ``x[idx] *= y`` and return the updated array."""
871
- return self ._iop ("multiply" , operator .mul , y , copy = copy , xp = xp )
875
+ return self ._iop ("multiply" , operator .imul , y , copy = copy , xp = xp )
872
876
873
877
def divide (
874
878
self ,
@@ -878,7 +882,7 @@ def divide(
878
882
xp : ModuleType | None = None ,
879
883
) -> Array : # numpydoc ignore=PR01,RT01
880
884
"""Apply ``x[idx] /= y`` and return the updated array."""
881
- return self ._iop ("divide" , operator .truediv , y , copy = copy , xp = xp )
885
+ return self ._iop ("divide" , operator .itruediv , y , copy = copy , xp = xp )
882
886
883
887
def power (
884
888
self ,
@@ -888,7 +892,7 @@ def power(
888
892
xp : ModuleType | None = None ,
889
893
) -> Array : # numpydoc ignore=PR01,RT01
890
894
"""Apply ``x[idx] **= y`` and return the updated array."""
891
- return self ._iop ("power" , operator .pow , y , copy = copy , xp = xp )
895
+ return self ._iop ("power" , operator .ipow , y , copy = copy , xp = xp )
892
896
893
897
def min (
894
898
self ,
0 commit comments