Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: Check labels arg when kwargs passed in Axis.set_ticks() #24334

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
Nov 14, 2022

Conversation

j1642
Copy link
Contributor

@j1642 j1642 commented Nov 1, 2022

PR Summary

Axis.set_ticks() allows kwargs to pass without using them if labels=None.

With these changes, Axis.set_ticks() now raises an exception when labels=None and kwargs are passed.
Does this change need API doc updates?

Resolves #24273.

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

  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@j1642 j1642 force-pushed the validate-set_ticks-kwargs branch 3 times, most recently from 36011e8 to 86c94c1 Compare November 4, 2022 22:48
Copy link
Member

@ksunden ksunden left a comment

Choose a reason for hiding this comment

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

I'm not fully clear why we need to be checking that the kwargs are only Text properties here... the end result if you pass something that is not is an AttributeError being raised anyway.

I suppose you could make an argument that you want to avoid setting the locations if you cannot also set the labels (preserving it as an atomic operation) but I'm not fully convinced that is needed here.
If that is the goal, I think we could come up with many more places that would require similar checks, and even additional checks on this method (e.g. insuring that the length of the labels is equal to the length of the provided locations... this is already checked deeper in the call stack, and even mentions set_ticks in the error message already)

Even if atomic operation is desirable here, I might advocate for a "forgiveness" approach, where we try to do everything, catch it, reset to original positions and reraise.
Do other maintainers have opinions here?

I am all for erroring out rather than silently dropping kwargs if labels are not provided, though.

@j1642
Copy link
Contributor Author

j1642 commented Nov 6, 2022

Simplifying the changes to only checking if labels is set when kwargs are passed seems good, from my perspective. I overlooked that kwargs are already checked for Text property membership.

@j1642 j1642 force-pushed the validate-set_ticks-kwargs branch 2 times, most recently from c6741c4 to 97058fc Compare November 6, 2022 19:42
@j1642 j1642 force-pushed the validate-set_ticks-kwargs branch from 97058fc to d9cd5cd Compare November 8, 2022 16:15
@j1642 j1642 changed the title ENH: Validate kwargs in Axis.set_ticks() ENH: Check labels arg when kwargs passed in Axis.set_ticks() Nov 11, 2022
@j1642
Copy link
Contributor Author

j1642 commented Nov 14, 2022

Hi, is this PR ready for merging?

@timhoffm timhoffm added this to the v3.7.0 milestone Nov 14, 2022
@timhoffm timhoffm merged commit 652d317 into matplotlib:main Nov 14, 2022
@timhoffm
Copy link
Member

Thanks @j1642 !

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.

[ENH]: Axes.set_xticks/Axis.set_ticks only validates kwargs if ticklabels are set, but they should
3 participants