Skip to content

Better handling of scalars to plt.subplot(). Fixes #880 - #1092

Merged
pelson merged 1 commit into
matplotlib:masterfrom
pelson:subplot_int
May 14, 2013
Merged

pelson merged 1 commit into
matplotlib:masterfrom
pelson:subplot_int

Conversation

@pelson

@pelson pelson commented Aug 15, 2012

Copy link
Copy Markdown
Member

No description provided.

Comment thread lib/matplotlib/tests/test_axes.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.

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
Copy Markdown
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
Copy Markdown
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

pelson commented Aug 19, 2012

Copy link
Copy Markdown
Member Author

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

mdboom commented Aug 19, 2012

Copy link
Copy Markdown
Member

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

pelson commented Aug 20, 2012

Copy link
Copy Markdown
Member Author

Ok. I will see what can be done.

@dmcdougall

Copy link
Copy Markdown
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
Copy Markdown
Member

Did we reach a consensus on this?

@efiring

efiring commented Jan 18, 2013

Copy link
Copy Markdown
Member

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

@dmcdougall

Copy link
Copy Markdown
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

pelson commented Apr 12, 2013

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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

pelson commented Apr 12, 2013

Copy link
Copy Markdown
Member Author

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