8000 Deprecate setting Axis.major.locator to non-Locator; idem for Formatters by anntzer · Pull Request #13851 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Deprecate setting Axis.major.locator to non-Locator; idem for Formatters #13851

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
Apr 21, 2019

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Apr 2, 2019

See changelog.

This is so that we can actually add new APIs to the base class (e.g.
format_ticks; tick_deconflict (however that one ends up being named)
and actually benefit from it in the rest of the codebase without
worrying that third-party locators/formatters do not inherit from the
base class (note that inheriting from the base class does not preclude
third-party locators/formatters from completely redefining all methods,
so this does not limit them).

(e.g. https://github.com/matplotlib/matplotlib/pull/13826/files#diff-52127080e2783464f529df684d82d476R1319)

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 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

See changelog.

This is so that we can actually add new APIs to the base class (e.g.
format_ticks; tick_deconflict (however that one ends up being named)
and actually benefit from it in the rest of the codebase without
worrying that third-party locators/formatters do not inherit from the
base class (note that inheriting from the base class does not preclude
third-party locators/formatters from completely redefining all methods,
so this does not limit them).
Setting ``Axis.major.locator``, ``Axis.minor.locator``, ``Axis.major.formatter``
or ``Axis.minor.formatter`` to an object that is not a subclass of `Locator` or
`Formatter` (respectively) is deprecated. Note that these attributes should
usually be set using `Axis.set_major_locator`, `Axis.set_minor_locator`, etc.
Copy link
Member
@timhoffm timhoffm Apr 2, 2019

Choose a reason for hiding this comment

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

Should they be set at all directly on the ticker? I don't think so at least for locators, because Axis.set_major_locator ensures that the formatter knows the locator, which is not guaranteed when setting Axis.major.locator.

So maybe add _set_locator() and _set_formatter() for the internal API. And deprecate property setter for all inputs.

Copy link
Contributor Author
@anntzer anntzer Apr 2, 2019

Choose a reason for hiding this comment

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

Well, you get to argue about https://github.com/matplotlib/matplotlib/pull/13826/files#diff-52127080e2783464f529df684d82d476R1319 with @tacaswell then :)

(Note that we could move the call to _set_locator in locator.setter, though.)

Copy link
Member

Choose a reason for hiding this comment

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

I don't see the point. The linked diff does not assign to axis.major.locator or axis.major.formatter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does getattr(self.minor.locator, "remove_overlaps", True) instead of the simpler self.minor.locator.remove_overlaps (note that remove_overlaps is in the base Locator class) specifically to handle the case of a locator not inheriting from Locator.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I see that we jump through some hoops to support non-Locator instances as locator.

But _set_locator() would be living in TickHelper, which hopefully nobody has replaced. AFAICS non-Locator objects would still work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I don't get what you're saying about TickHelper. Did you mean Ticker (which is not the same)?

Copy link
Member
@efiring efiring left a comment

Choose a reason for hiding this comment

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

Seems like a good idea.

@@ -640,8 +640,36 @@ class Ticker(object):
formatter : `matplotlib.ticker.Formatter` subclass
Determines the format of the tick labels.
"""
locator = None
formatter = None
Copy link
Member

Choose a reason for hiding this comment

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

I hope that removing these (public) class attributes isn't going to trip anyone up. Maybe that would involve such an obscure use case that it won't happen.

Copy link
Member

Choose a reason for hiding this comment

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

We did just have that issue, but in this case I suspect it will be ok.

These lines go back to d78e6c4 and I suspect it was done done to make sure that Ticker sub-classes always had the attributes. Putting something into these attributes at the class level does not really make sense.

@tacaswell tacaswell added this to the v3.2.0 milestone Apr 20, 2019
@efiring efiring merged commit 5c791a8 into matplotlib:master Apr 21, 2019
@anntzer anntzer deleted the locform branch April 21, 2019 08:32
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.

4 participants
0