Skip to content

In-place addition (and other operations) of masked array invoke extra casting check #7991

@jjhelmus

Description

@jjhelmus

In-place addition and other in-place operations on masked arrays where the mask is not nomask results in an ufunc casting rule check which is not performed when the operation is performed normally (not in-place) or on a normal ndarray.

Example

>>> import numpy as np
>>> x = np.ma.array([0, 1, 2], dtype='uint8', mask=False)
>>> x += 4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jhelmus/anaconda/lib/python3.5/site-packages/numpy/ma/core.py", line 4025, in __iadd__
    getdata(other)))
TypeError: Cannot cast ufunc add output from dtype('int64') to dtype('uint8') with casting rule 'same_kind'
>>> # Not in place
>>> x = x + 4
>>> # on a normal ndarray
>>> x = np.array([0, 1, 2], dtype='uint8')
>>> x += 4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions