Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: ndarray.put disrespects flags.writeable = False #4465

Closed
@immerrr

Description

@immerrr

It seems that ndarray.put disrespects writeable flag unlike other fancy indexing setters:

In [1]: np.__version__
Out[1]: '1.8.0'

In [2]: np.arange(10)
Out[2]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

In [3]: _2.flags.writeable = False

In [4]: _2[[1,2,3]] = 100
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-6b16d30888f3> in <module>()
----> 1 _2[[1,2,3]] = 100

ValueError: assignment destination is read-only

In [5]: _2.flat[[1,2,3]] = 100
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-ad5ff20cf609> in <module>()
----> 1 _2.flat[[1,2,3]] = 100

ValueError: underlying array is read-only

In [6]: _2.put([1,2,3], 100)

In [7]: _2
Out[7]: array([  0, 100, 100, 100,   4,   5,   6,   7,   8,   9])

At least 1.8.0 is affected, but given that PyArray_PutTo doesn't include PyArray_FailUnlessWriteable in master, I'd say master is affected too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions