8000 BUG: immutable _arraymethod function in ma.core by jjhelmus · Pull Request #6588 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: immutable _arraymethod function in ma.core #6588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2015

Conversation

jjhelmus
Copy link
Contributor

Replace the _arraymethod class in ma.core with a function factory which
returns class method wrappers around basic array methods. These methods are
bound to the MaskedArray instance and are immutable.

Previously _arraymethod was a class which would incorrectly operate on the
MaskedArray object which last accessed the particular named function.

closes #5247

Replace the _arraymethod class in ma.core with a function factory which
returns class method wrappers around basic array methods. These methods are
bound to the MaskedArray instance and are immutable.

Previously _arraymethod was a class which would incorrectly operate on the
MaskedArray object which last accessed the particular named function.

closes numpy#5247
@jjhelmus
Copy link
Contributor Author

Should be noted that wrapping methods in this manner results in a change in their call signatures. This does not seem to effect the generated documentation but may be an issue.

>>> import numpy as np
>>> a = np.ma.arange(10)
>>> help(a.copy)

New call signature:

Help on method copy in module numpy.ma.core:

copy(self, *args, **params) method of numpy.ma.core.MaskedArray instance
    a.copy(order='C')
...

Old signature

Help on _arraymethod in module numpy.ma.core:

copy(...)
    a.copy(order='C')
...

@ahaldane
Copy link
Member

Looks good to me.

The signature change isn't a problem - python doesn't have access to the signatures of ndarray methods anyway since they are implemented in C.

This makes me think that the other decorators there (_frommethod, _convert2ma) would be cleaner as functions instead of classes, although I don't think there are any bugs caused by leaving them as classes.

I'd like let this sit for a day or so in case anyone else wants to look, and then merge.

@ahaldane
Copy link
Member
ahaldane commented Nov 1, 2015

All right, merging. Thanks a lot @jjhemlus!

ahaldane added a commit that referenced this pull request Nov 1, 2015
BUG: immutable _arraymethod function in ma.core
@ahaldane ahaldane merged commit 7389b51 into numpy:master Nov 1, 2015
@jjhelmus
Copy link
Contributor Author
jjhelmus commented Nov 2, 2015

Thanks for reviewing this @ahaldane. I'll have a look at the other decorates in the module and see if there is a compelling case to covert them to functions.

@jjhelmus jjhelmus deleted the fix_copy_mutable branch November 2, 2015 21:14
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.

Class _arraymethod in ma.core is a descriptor, yet mutable.
3 participants
0