Clarify error when plot() args have bad shapes.#5607
Clarify error when plot() args have bad shapes.#5607tacaswell merged 1 commit intomatplotlib:masterfrom
Conversation
lib/matplotlib/axes/_base.py
Outdated
There was a problem hiding this comment.
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])
There was a problem hiding this comment.
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.
|
I am 50/50 on backporting this to 2.0 |
880b068 to
dd4dc1a
Compare
|
Updated error message. |
ENH: Clarify error when plot() args have bad shapes.
ENH: Clarify error when plot() args have bad shapes.
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.