Skip to content

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

Merged
jklymak merged 1 commit into
matplotlib:mainfrom
anntzer:misspelled-data-key
May 22, 2022
Merged

Improve error for invalid format strings / misspelled data keys.#23088
jklymak merged 1 commit into
matplotlib:mainfrom
anntzer:misspelled-data-key

Conversation

@anntzer

@anntzer anntzer commented May 21, 2022

Copy link
Copy Markdown
Contributor

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 added the API: argument checking Validation of acceptable argument values label May 21, 2022
Comment thread lib/matplotlib/axes/_base.py Outdated
@anntzer
anntzer force-pushed the misspelled-data-key branch from bd952fb to d7bf480 Compare May 21, 2022 21:03


def _process_plot_format(fmt):
def _process_plot_format(fmt, *, ambiguous_fmt_datakey=False):

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.

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

@anntzer anntzer May 21, 2022

Copy link
Copy Markdown
Contributor Author

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.

@greglucas greglucas left a comment

Copy link
Copy Markdown
Contributor

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.

except ValueError:
pass # No, not just a color.

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

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

jklymak commented May 22, 2022

Copy link
Copy Markdown
Member

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

Labels

API: argument checking Validation of acceptable argument values

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Confusing error messages

5 participants