-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Better handling of scalars to plt.subplot(). Fixes #880 #1092
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
Conversation
|
||
@cleanup | ||
def test_subplot_key_hash(): | ||
ax = plt.subplot(np.float64(5.5), np.int64(1), np.float64(1.2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it not make more sense to raise an exception immediately if subplot args are not integer values (though perhaps not necessarily integer dtypes)? I don't see how a value like 5.5 can be anything but a programming error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to agree. It would break backwards compatibility though, as passing a python float
is currently handled by casting to an int
. This approach doesn't break that "feature". Preferences?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a spurious feature at best. I understand it breaks backward compatibility -- but if a float is being passed in, I think it's better to let the user know there was a mistake. We can add a CHANGELOG entry to this effect.
Realistically, I don't think I can spend the time on this PR to get this into 1.2.x. It's a pretty minor bug which I could live with in a 1.2 release. Agree? |
As subplot is such a frequently used function, I'd like the benefit of having this in early in case there are any unexpected repercussions. So, yes, we should probably hang off -- but I wouldn't be opposed if it went in a few days late -- we have three weeks lead time until the rc1. |
Ok. I will see what can be done. |
I'm in favour of raising an exception if the user tries to pass in something that isn't an integer. Since this won't make it into 1.2, it's okay to break backwards compatibility. On the other hand, it seems that passing nonintegers as indices to arrays does not raise an error: >>> import numpy as np
>>> a = np.array([[1, 2], [3, 4]])
>>> a[0.1, 1.2]
2 Given that an error is not raised in this case, I can see the argument for supporting noninteger indices. Personally, though, I would never use this 'feature'. |
Did we reach a consensus on this? |
I think the consensus was that we should raise an Exception if int(v) != v. |
@efiring That's what I thought. Thanks. I'm not sure the 1.2.1 milestone is appropriate for this PR. Raising an exception if |
Not sure when it happened, but the problem no longer exists on master (could be from my own PR some time ago which related to projections, but I'm not certain). This PR is therefore just an addition of a test. |
I might have fixed it when I added code to detect if one might have |
Cool. Good job! 😄 |
Adds a test for subplot float handling (#880)
No description provided.