Skip to content

2to3: Apply nonzero fixer. #3241

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
Apr 14, 2013
Merged

Conversation

charris
Copy link
Member

@charris charris commented Apr 13, 2013

In Python 3 the __nonzero__ class method is replaced by __bool__.
This only affects the MaskedArray class in numpy/oldnumeric/ma.py file
and the simplest solution is to provide both methods. I have my doubts
that the fixed up Python 3 version was correct or even tested, but I
think the current solution should work for as long as oldnumeric stays
in numpy.

Closes #3073.

In Python 3 the `__nonzero__` class method is replaced by `__bool__`.
This only affects the MaskedArray class in numpy/oldnumeric/ma.py file
and the simplest solution is to provide both methods. I have my doubts
that the fixed up Python 3 version was correct or even tested, but I
think the current solution should work for as long as oldnumeric stays
in numpy.

Closes numpy#3073.
@charris
Copy link
Member Author

charris commented Apr 14, 2013

Still looks good in the morning. This is a minimal change that adds a method expected by Python 3. 2to3 would just rename the nonzero method, so the copy here should have the same result.

charris added a commit that referenced this pull request Apr 14, 2013
@charris charris merged commit 61c5ac6 into numpy:master Apr 14, 2013
@charris charris deleted the 2to3-apply-nonzero-fixer branch April 14, 2013 14:33
@njsmith
Copy link
Member

njsmith commented Apr 14, 2013

Better than copy/pasting the code would be to call nonzero or just write

bool = nonzero

Not a big deal though.
On 14 Apr 2013 15:34, "Charles Harris" notifications@github.com wrote:

Still looks good in the morning. This is a minimal change that adds a
method expected by Python 3. 2to3 would just rename the nonzero method,
so the copy here should have the same result.


Reply to this email directly or view it on GitHubhttps://github.com//pull/3241#issuecomment-16351942
.

@charris
Copy link
Member Author

charris commented Apr 14, 2013

Heh, yeah. I did consider it, but copy paste was less work ;) Plus if we ever drop 2.7, say in ten years of so, and this module is still around, we can erase nonzero.

@njsmith
Copy link
Member

njsmith commented Apr 15, 2013

Sure. And I guess it's not too likely they'll diverge given that no-one
works on np.ma...

On Sun, Apr 14, 2013 at 10:42 PM, Charles Harris
notifications@github.comwrote:

Heh, yeah. I did consider it, but copy paste was less work ;) Plus if we
ever drop 2.7, say in ten years of so, and this module is still around, we
can erase nonzero.


Reply to this email directly or view it on GitHubhttps://github.com//pull/3241#issuecomment-16360183
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants