Skip to content

BUG: Added exception for casting numpy.ma.masked to long - #9817

Merged
eric-wieser merged 1 commit into
numpy:masterfrom
kenogo:master
Oct 5, 2017
Merged

eric-wieser merged 1 commit into
numpy:masterfrom
kenogo:master

Conversation

@kenogo

@kenogo kenogo commented Oct 3, 2017 •

Copy link
Copy Markdown

This fixes #9751.

@eric-wieser

Copy link
Copy Markdown
Member

Needs a test, and the commit messages should start with BUG:

@kenogo kenogo changed the title Added exception for casting numpy.ma.masked to long BUG: Added exception for casting numpy.ma.masked to long Oct 3, 2017
@kenogo

kenogo commented Oct 3, 2017 •

Copy link
Copy Markdown
Author

@eric-wieser Alright. Since the long datatype no longer exists in Python 3, how can I make a test that only runs for Python 2?

@kenogo

kenogo commented Oct 3, 2017

Copy link
Copy Markdown
Author

Okay this should be it

@kenogo

kenogo commented Oct 3, 2017 •

Copy link
Copy Markdown
Author

Oh damn it, I'm tired. First accidentally named the test function test_coercion_int. Now renamed it correctly to test_coercion_long but somehow wrote float in my commit message... That should be all for this bug though.

@kenogo

kenogo commented Oct 3, 2017 •

Copy link
Copy Markdown
Author

Ok last commit message is now edited accordingly.

Comment thread numpy/ma/tests/test_core.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is kinda unnecessary, as it actually tests exactly the same thing as above. long(np.ma.masked) would be a good test to have somewhere though.

Also, you want skipif, not knownfailureif here - the latter is reserved for things that make sense to fix in future.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I test with an int in nose, it automatically tests int for Python 3 and int and long for Python 2? This means I should just get rid of my new testing function and I'm done? I was already wondering why you added a knownfailureif decorator for test_coercion_int, this explains it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nose isn't doing anything special here.

The old bug was not actually caused by long there, but by any integer type, even np.int8 - because internally, numpy was calling long.

It would still be good to have a long(np.ma.masked) test somewhere. I'd hope we already have one for int which it could go alongside, but I might be overly optimistic there.

Comment thread numpy/ma/core.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix itself looks fine, by the way :)

@kenogo

kenogo commented Oct 4, 2017

Copy link
Copy Markdown
Author

So is there anything left to do for me or can this be merged?

@eric-wieser

Copy link
Copy Markdown
Member

See the hidden comment above

@kenogo

kenogo commented Oct 4, 2017

Copy link
Copy Markdown
Author

@eric-wieser Oh I totally overread that. I hope I got what you wanted correctly... Please elaborate if I misunderstood you.

Comment thread numpy/ma/tests/test_core.py Outdated

@eric-wieser eric-wieser Oct 4, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better as assert_raises(MaskError, int, np.ma.masked). Here you do need a test for long as well.

I think there might already be a test for this kind of thing elsewhere. Grepping for assert_raises(MaskError ought to find it

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eric-wieser Nope a test for this doesn't exist yet.

@kenogo

kenogo commented Oct 4, 2017

Copy link
Copy Markdown
Author

That's it I think

@eric-wieser

Copy link
Copy Markdown
Member

Looks good to me. Those 6 commits need squashing into one or two (there aren't 6 different changes being made here), but I can do that if you don't want to.

@kenogo

kenogo commented Oct 4, 2017

Copy link
Copy Markdown
Author

@eric-wieser Yeah I'm not sure how to do that. Go ahead.

TST: Added test_coercion_long and removed knownfailure from test_coercion_int
@kenogo

kenogo commented Oct 4, 2017 •

Copy link
Copy Markdown
Author

@eric-wieser Nevermind, I figured it out :)

@eric-wieser

Copy link
Copy Markdown
Member

Thanks for taking the time to learn how to do that, and thanks for the contribution :)

@eric-wieser
eric-wieser merged commit 98e7efc into numpy:master Oct 5, 2017
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.

BUG: Casting np.ma.masked to long is legal

3 participants