Skip to content

Improve error for invalid format strings / misspelled data keys. #23088

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
May 22, 2022

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented May 21, 2022

PR Summary

Closes #23083 (IMO).
FWIW I agree that the current behavior can be a bit confusing (I'm not sure really like the whole data kwarg business due to the confusion it creates in combination with plot()'s weird signatures, but that ship has sailed long ago).

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@anntzer anntzer force-pushed the misspelled-data-key branch from bd952fb to d7bf480 Compare May 21, 2022 21:03
@@ -118,7 +118,7 @@ def __call__(self, ax, renderer):
self._transform - ax.figure.transSubfigure)


def _process_plot_format(fmt):
def _process_plot_format(fmt, *, ambiguous_fmt_datakey=False):
Copy link
Member

Choose a reason for hiding this comment

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

Bonus points if you copy the docstring for the parameter here as well.

Copy link
Contributor Author

@anntzer anntzer May 21, 2022

Choose a reason for hiding this comment

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

The docstring was already not numpydoc'ed (and doing properly so is slightly messy due to, well, the messy API), so I'll skip these points for now.

Copy link
Contributor

@greglucas greglucas left a comment

Choose a reason for hiding this comment

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

Minor wording suggestion to avoid the double negative, but it looks good to me.

@@ -163,31 +163,31 @@ def _process_plot_format(fmt):
except ValueError:
pass # No, not just a color.

errfmt = ("{!r} is neither a data key nor a valid format string ({})"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
errfmt = ("{!r} is neither a data key nor a valid format string ({})"
errfmt = ("{!r} is not a data key or a valid format string ({})"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

Copy link
Member

Choose a reason for hiding this comment

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

This is a bit of an Oxford comma thing, but I would tend to say neither...nor here. It's correct and a bit more formal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do prefer neither/nor, so I'll go back to that :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. :) I'm not formal enough in my speaking it seems!

@anntzer anntzer force-pushed the misspelled-data-key branch 2 times, most recently from b40e6dd to d7bf480 Compare May 22, 2022 16:21
@jklymak
Copy link
Member

jklymak commented May 22, 2022

I'll take the liberty of merging because I don't think @greglucas was that worried about the grammar change ;-)

@jklymak jklymak merged commit feb1ca1 into matplotlib:main May 22, 2022
@anntzer anntzer deleted the misspelled-data-key branch May 22, 2022 16:51
@QuLogic QuLogic added this to the v3.6.0 milestone May 24, 2022
@QuLogic QuLogic changed the title Improve error for invalid format strings / mispelled data keys. Improve error for invalid format strings / misspelled data keys. Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Confusing error messages
5 participants