[Numpy-discussion] Regression: in-place operations (possibly intentional)

Nathaniel Smith njs at pobox.com
Thu Sep 20 17:48:26 EDT 2012

On Wed, Sep 19, 2012 at 1:08 AM, Charles R Harris
<charlesr.harris at gmail.com> wrote:
> <snip>
> The relevant setting is in numpy/core/include/numpy/ndarraytypes.h
> I think that if we want to raise a warning we could define a new rule,
> Which would do the same as unsafe, only raise a warning on the way.


Query: I would have thought that NPY_DEFAULT_ASSIGN_CASTING would
determine the default casting used for assignments. But in current

>>> a = np.zeros(3, dtype=int)
>>> a[0] = 1.1
>>> a
array([1, 0, 0])

In fact, this variable seems to only be used by PyArray_Std,
PyArray_Round, and ufuncs. Okay, so, NPY_DEFAULT_ASSIGN_CASTING is
just misnamed, but -- what casting rule *should* plain old assignment
follow? I'd think same_kind casting is probably a good default here
for the same reason it's a good default for ufuncs, and because a += b
really should be the same as a = a + b. But, the only problem is, how
could you override it if desired? a.__setitem__(0, casting="unsafe")?


More information about the NumPy-Discussion mailing list