8000 Clarifying an error message by AllenDowney · Pull Request #11772 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Clarifying an error message #11772

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
Jul 25, 2018
Merged

Conversation

AllenDowney
Copy link
Contributor

PR Summary

If the format string is None, you get a message that says "x and y must not be None", which is confusing.

I'm suggesting a revised error message.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@story645
Copy link
Member

Thanks for the contribution! (as an aside, I recommend "Think Python" to everyone)

Can you please provide sample code that triggered this error? I'm having trouble figuring out which argument was the format string.

@AllenDowney
Copy link
Contributor Author

Sample code:

plt.plot(1, 1, None)

Copy link
Member
@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, but I don't think you should have got to this Error if the third positional argument was not a string. So, I'm blocking because I think we should fix the actual bug...

@@ -350,7 +350,7 @@ def _plot_args(self, tup, kwargs):
# to one element array of None which causes problems
# downstream.
if any(v is None for v in tup):
raise ValueError("x and y must not be None")
raise ValueError("x, y, and format string must not be None")
Copy link
Member

Choose a reason for hiding this comment

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

Huh, you shouldn't have got here according to the logic above.... I think you've actually found a bug, not a documentation error...

@AllenDowney
Copy link
Contributor Author
AllenDowney commented Jul 25, 2018 via email

@anntzer
Copy link
Contributor
anntzer commented Jul 25, 2018

It's not clear to me why we should accept None (an empty string is even shorter to type), so I agree with the original PR. @jklymak Not sure what is the logic error you're seeing...

@AllenDowney
Copy link
Contributor Author
AllenDowney commented Jul 25, 2018 via email

@jklymak
Copy link
Member
jklymak commented Jul 25, 2018

The logic in _plot_args checks if the last element of the tuple is a string or not.

However, _plot_args is not being passed a three-tuple in this case. It gets passed a 2-tuple (x and y) and then a 1-tuple (None). That seems a bit strange to me...

@anntzer
Copy link
Contributor
anntzer commented Jul 25, 2018

@AllenDowney But certainly you can make the parsing parse whatever input into "" instead of None?

@jklymak That's because we're treating (or trying to treat) this as we do for

plot([1, 2, 3], [4, 5, 6], [7, 8, 9])

i.e. plot [1, 2, 3] against [4, 5, 6] and (implicit index of [0, 1, 2]) against [7, 8, 9]. Is that a good API? Probably not (looks more likely to hide logic bugs).

@jklymak jklymak dismissed their stale review July 25, 2018 15:28

Incorrect assumption

@jklymak
Copy link
Member
jklymak commented Jul 25, 2018

Fair enough. Boy is the plot API all over the place...

@anntzer
Copy link
Contributor
anntzer commented Jul 25, 2018

Ah but I guess

plot([1, 2, 3], [4, 5, 6], "r", [7, 8, 9], "b")

should be considered as "fine" (as in, likely not a logic bug) so heh...

@jklymak jklymak merged commit fbc4f4c into matplotlib:master Jul 25, 2018
@jklymak
Copy link
Member
jklymak commented Jul 25, 2018

Thanks @AllenDowney

@AllenDowney
Copy link
Contributor Author

Thank you all.

@tacaswell tacaswell added this to the v3.0 milestone Jul 25, 2018
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
0