Skip to content
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

Clarify error when plot() args have bad shapes. #5607

Merged
merged 1 commit into from Dec 5, 2015

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Dec 3, 2015

When I see the error "x and y must have the same dimensions", typically the first thing I do is to re-run the thing with a print of the shapes just before the call to plot() (or do this via pdb), and then I think about what went wrong. This is a minor patch that would save this step.

@@ -220,9 +220,11 @@ def _xy_from_xy(self, x, y):
x = _check_1d(x)
y = _check_1d(y)
if x.shape[0] != y.shape[0]:
raise ValueError("x and y must have same first dimension")
raise ValueError("x (shape: {}) and y (shape: {}) must have same "
"first dimension".format(x.shape, y.shape))
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for this. The double parens are a bit jarring though, and this gives more info than one needs. Maybe:

"x and y must have same first dimension.  Got {} and {}.".format(x.shape[0], y.shape[0])

Copy link
Member

Choose a reason for hiding this comment

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

Nah, I like seeing the whole shape info. Just having the first dimension of
the shape doesn't always clue you into what went wrong. Perhaps I
transposed one of the arrays? Maybe I passed in a completely different
array than I intended? Only printing the first dimensions size will likely
still have me going back and printing out the full shape info.

That said, I would like to see the original message kept intact in the
beginning of the string, only adding the new stuff at the end.

On Thu, Dec 3, 2015 at 8:03 AM, Michael Droettboom <notifications@github.com

wrote:

In lib/matplotlib/axes/_base.py
#5607 (comment):

@@ -220,9 +220,11 @@ def _xy_from_xy(self, x, y):
x = _check_1d(x)
y = _check_1d(y)
if x.shape[0] != y.shape[0]:

  •        raise ValueError("x and y must have same first dimension")
    
  •        raise ValueError("x (shape: {}) and y (shape: {}) must have same "
    
  •                         "first dimension".format(x.shape, y.shape))
    

Thanks for this. The double parens are a bit jarring though, and this
gives more info than one needs. Maybe:

"x and y must have same first dimension. Got {} and {}.".format(x.shape[0], y.shape[0])


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/5607/files#r46548308.

Copy link
Member

Choose a reason for hiding this comment

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

I am with @WeatherGod on both points.

@tacaswell tacaswell added this to the proposed next point release (2.1) milestone Dec 3, 2015
@tacaswell
Copy link
Member

I am 50/50 on backporting this to 2.0

@anntzer
Copy link
Contributor Author

anntzer commented Dec 3, 2015

Updated error message.

tacaswell added a commit that referenced this pull request Dec 5, 2015
ENH: Clarify error when plot() args have bad shapes.
@tacaswell tacaswell merged commit 2f65b5b into matplotlib:master Dec 5, 2015
@anntzer anntzer deleted the clarify-bad-shape-error branch December 5, 2015 00:24
tacaswell added a commit that referenced this pull request Dec 5, 2015
ENH: Clarify error when plot() args have bad shapes.
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.

None yet

4 participants