-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Init MaxNLocator params only once #12998
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
Conversation
I'd suggest just making the signature explicit
and kill default_params... |
Formally, making the signature explicit is backwards incompatible.
How much do we care about these things? |
I really meant "do the necessary deprecation dance to ultimately make the signature explicit". |
be4008b
to
e881dc1
Compare
deprecated and will be removed in a future version. The defaults are not | ||
supposed to be user-configurable. | ||
|
||
``matplotlib.ticker.MaxNLocator`` and it's ``set_params`` method will issue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its
lib/matplotlib/ticker.py
Outdated
@@ -1905,6 +1922,11 @@ def _staircase(steps): | ||
|
||
def set_params(self, **kwargs): | ||
"""Set parameters within this locator.""" | ||
if set(kwargs) - self._supported_kwargs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just pop the kwargs at every if clause below and then check if kwargs is empty. (Note that this check will need to stay even after the deprecation period is over and the signature of init changed, as we need to distinguish between a kwarg not passed to set_params and a kwarg set to its default.)
e881dc1
to
7c46d33
Compare
lib/matplotlib/ticker.py
Outdated
self._integer = kwargs['integer'] | ||
self._integer = kwargs.pop('integer') | ||
if kwargs: | ||
param = next(k for k in kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do k, _ = kwargs.popitem()
or k, *_ = kwargs
which are both more natural IMO, but it's not a big deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do tomorrow (and also fix the flake8 issue)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments handled.
7c46d33
to
a1179e9
Compare
a1179e9
to
f084e0d
Compare
According to @jklymak in SciTools/cartopy#1299, this change will break some bits of Cartopy. |
PR Summary
This makes creating
MaxNLocator
a bit faster (~3ms -> ~2ms) by callingset_params
only once.Edit:
Original PR was just:
self.set_params(**{**self._default_params, **kwargs})
.Additionally, I've introduced preparatory steps to make the signature explicit, which needs a lot of deprecation logic. It's still easiest to make the signature only explicit after the deprecation period is over.