Skip to content

BUG: make data attribute of ndarray read-only - #5958

Closed
jaimefrio wants to merge 1 commit into
numpy:masterfrom
jaimefrio:data_ro
Closed

jaimefrio wants to merge 1 commit into
numpy:masterfrom
jaimefrio:data_ro

Conversation

@jaimefrio

Copy link
Copy Markdown
Member

Fixes #1873

@jaimefrio

Copy link
Copy Markdown
Member Author

Haven't found any specific ndarray attribute tests, any suggestions on where could they go?

Also, if we agree to merge this it probably deserves a mention in the release notes.

@seberg

seberg commented Jun 11, 2015

Copy link
Copy Markdown
Member

+100, but do we want to take the chance of having to revert it again if there is enough complains, or should we just go for a VisibleDeprecationWarning with a scary text first?

@nouiz

nouiz commented Jun 11, 2015

Copy link
Copy Markdown
Contributor

Old version of Theano was doing the same at the C level in the past. But not now. We currently use PyArray_NewFromDescr. Is there an equivalent in python? We did this as we create our view ourself in some cases. Other people could do this in python.

But I agree, doing it by changing the data ptr is dangerous, so I would consider just raising an error to tell that this isn't supported anymore and tell if they are in the rare case of wanting to build there own view, they should use the equivalent in python of PyArray_NewFromDescr.

I would be surprised there is many complain, but we never know!

@seberg

seberg commented Jun 11, 2015

Copy link
Copy Markdown
Member

You can use the np.ndarray constructor, I guess? Though IIRC there was something about some types of buffers not being supported, but not sure.

@charris

charris commented Jun 13, 2015

Copy link
Copy Markdown
Member

If this goes in for 1.10, it needs a description in the release. But I admit being ambivalent, we already have so much that will likely break code somewhere...

@charris

charris commented Oct 3, 2015

Copy link
Copy Markdown
Member

May be a problem with f2py. IIRC, there is a place where the data pointer (and other stuff) is swapped. Swapping pointers is also something used in some C++ std classes; swap with pointer in local class and the pointer gets deallocated when the function exits. Anyway, we might want a special function for swapping ndarray structure contents when needed.

@charris

charris commented Dec 22, 2015

Copy link
Copy Markdown
Member

I think f2py changes the data pointer. C++ vectors have a swap method, ndarray could probably use the same. The functionality would be to swap the data contents of two ndarray structures. In C++ one of the two would be cleaned up when is when it went out of scope and we wouldn't have all that functionality in C, but could still be useful.

@seberg

seberg commented Dec 22, 2015

Copy link
Copy Markdown
Member

A swap method in the C-Api might make sense. I seem to remember people saying that they need it. I personally hope it should not be needed (almost?) ever, and it is dangerous buisness if the array is referenced elsewhere.... (I doubt C++ vectors widely use views?)
Anyway, I guess having a function for it still beats writing the data pointer in the ndarray structure directly plus you can put a big warning flag on it ;).

@njsmith

njsmith commented Dec 22, 2015

Copy link
Copy Markdown
Member

We should perhaps also be trying not to add more code that requires refcnt
== 1, also, since perhaps there is somewhat more hope these days of numpy
being run on non-cpython implementations... (I know pypy, jython, and
pyston are all actively working on supporting real honest numpy through
their c api compatibility layers right now)

On Tue, Dec 22, 2015 at 11:00 AM, seberg [email protected] wrote:

A swap method in the C-Api might make sense. I seem to remember people
saying that they need it. I personally hope it should not be needed
(almost?) ever, and it is dangerous buisness if the array is referenced
elsewhere.... (I doubt C++ vectors widely use views?)
Anyway, I guess having a function for it still beats writing the data
pointer in the ndarray structure directly plus you can put a big warning
flag on it ;).

—
Reply to this email directly or view it on GitHub
#5958 (comment).

Nathaniel J. Smith -- http://vorpus.org

@homu

homu commented Feb 29, 2016

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #7275) made this pull request unmergeable. Please resolve the merge conflicts.

jaimefrio pushed a commit to jaimefrio/numpy that referenced this pull request Mar 22, 2016
@jaimefrio
jaimefrio deleted the data_ro branch March 28, 2016 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants