Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 1 commit into from
May 14, 2013

Conversation

pelson
Copy link
Member

@pelson pelson commented Aug 15, 2012

No description provided.


@cleanup
def test_subplot_key_hash():
ax = plt.subplot(np.float64(5.5), np.int64(1), np.float64(1.2))
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

@pelson
Copy link
Member Author

pelson commented Aug 19, 2012

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?

@mdboom
Copy link
Member

mdboom commented Aug 19, 2012

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.

@pelson
Copy link
Member Author

pelson commented Aug 20, 2012

Ok. I will see what can be done.

@dmcdougall
Copy link
Member

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'.

@dmcdougall
Copy link
Member

Did we reach a consensus on this?

@efiring
Copy link
Member

efiring commented Jan 18, 2013

I think the consensus was that we should raise an Exception if int(v) != v.

@dmcdougall
Copy link
Member

@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 int(v) != v will break code, throwing an error were an error was not thrown before. Granted, I am of the opinion that I do not interpret passing a non-integer value as an index as anything but a programming error, but I feel the user should be warned in advance (e.g., by deprecating first) before making this change.

@ghost ghost assigned pelson Feb 4, 2013
@pelson
Copy link
Member Author

pelson commented Apr 12, 2013

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.

@WeatherGod
Copy link
Member

I might have fixed it when I added code to detect if one might have
intended to use subplots() instead of subplot() and vice-versa. I forget
which PR that was, though.

@pelson
Copy link
Member Author

pelson commented Apr 12, 2013

I might have fixed it when I added code to detect if one might have intended to use subplots() instead of subplot() and vice-versa. I forget which PR that was, though.

Cool. Good job! 😄

pelson added a commit that referenced this pull request May 14, 2013
Adds a test for subplot float handling (#880)
@pelson pelson merged commit 47193ee into matplotlib:master May 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants