X Tutup
Skip to content

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

Merged
tacaswell merged 1 commit intomatplotlib:masterfrom
anntzer:clarify-bad-shape-error
Dec 5, 2015
Merged

Clarify error when plot() args have bad shapes.#5607
tacaswell merged 1 commit intomatplotlib:masterfrom
anntzer:clarify-bad-shape-error

Conversation

@anntzer
Copy link
Copy Markdown
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.

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.

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

I am 50/50 on backporting this to 2.0

@anntzer anntzer force-pushed the clarify-bad-shape-error branch from 880b068 to dd4dc1a Compare December 3, 2015 17:14
@anntzer
Copy link
Copy Markdown
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.

4 participants

X Tutup