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

Skip to content

FIX: undeprecate MaxNLocator default_params #13992

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

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Apr 20, 2019

PR Summary

Closes #13991

As pointed out in #13991 the deprecation (in #12998) of the global default_params will break Cartopy, and cartopy seems to do the right thing for the current way MaxNLocator is set up, so this breakage seems undesirable...

Cartopy's problem can be tested as:

import matplotlib.ticker as mticker

class FancyLocator(mticker.MaxNLocator):
    default_params = mticker.MaxNLocator.default_params.copy()
    default_params.update(nbins=8, dms=False)

loc0 = mticker.MaxNLocator()
loc1 = FancyLocator()

Which gives the error:

Traceback (most recent call last):
  File "testLocator.py", line 3, in <module>
    class FancyLocator(mticker.MaxNLocator):
  File "testLocator.py", line 4, in FancyLocator
    default_params = mticker.MaxNLocator.default_params.copy()
AttributeError: '_deprecated_property' object has no attribute 'copy'

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

@jklymak
Copy link
Member Author

jklymak commented Apr 20, 2019

BTW, looks like https://www.python.org/dev/peps/pep-0562/ will provide a way to deprecate the attribute w/o making it a property in 3.7.

@jklymak jklymak requested review from timhoffm and QuLogic April 20, 2019 04:27
@dstansby dstansby added this to the v3.1.0 milestone Apr 20, 2019
@dstansby dstansby added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Apr 20, 2019
@dstansby
Copy link
Member

Might be worth sticking that code snippet in as a test? Otherwise looks 👍 to me

@jklymak
Copy link
Member Author

jklymak commented Apr 20, 2019

I didn’t because I think we need to decide if Cartopy should be accessing default_params this way. Also, what is the proper way for a child locator to modify the defaults if not via this global? Finally if we don’t think this is correct why keep the global at all? It seems like a thoroughly confusing way to define the defaults.

@tacaswell
Copy link
Member

We can probably also use a custom descritor on the class, something like

class Foo:
    
    def __get__(self, obj, objtype):
        return objtype._default_params

class Bar:
    _default_params = {'a': 'b'}
    default_params = Foo()

but I am also 👍 on reverting this for 3.1 and re-addressing in 3.2.

@tacaswell
Copy link
Member

Will also need to remove the deprecation note.

@jklymak
Copy link
Member Author

jklymak commented Apr 20, 2019

Will also need to remove the deprecation note.

Removed the note....

The fancy workarounds to deprecate this are a bit beyond my ability. As I said, it seems that py3.7 will allow this to be deprecated in a straightforward way, so when we drop 3.6 we can do this. I think its a nice cleanup, but not worth breaking downstream packages for.

@tacaswell
Copy link
Member

I think pep562 is about module level, not class level attributes....

I would like @timhoffm to weigh on this one way or the other.

@@ -750,9 +750,6 @@ The following signature related behaviours are deprecated:
- Passing ``shade=None`` to `~.axes3d.Axes3D.plot_surface` is deprecated. This
was an unintended implementation detail with the same semantics as
``shade=False``. Please use the latter code instead.
- `matplotlib.ticker.MaxNLocator` and its *set_params* method will issue
Copy link
Member

Choose a reason for hiding this comment

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

This should stay as it refers to the code at https://github.com/matplotlib/matplotlib/pull/13992/files#diff-efde3b8d2ec4015b0fc910f1080cc492L2020 which has not ben reverted.

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

Thanks!

@dstansby dstansby merged commit 44d503e into matplotlib:master Apr 21, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Apr 21, 2019
tacaswell added a commit that referenced this pull request Apr 21, 2019
…992-on-v3.1.x

Backport PR #13992 on branch v3.1.x (FIX: undeprecate MaxNLocator default_params)
@anntzer
Copy link
Contributor

anntzer commented Apr 23, 2019

I think the deprecation should stay and cartopy should do the much simpler

class Foo(MaxNLocator):
    def __init__(self, *, nbins=8, dms=False, **kwargs):
        super().__init__(nbins=nbins, **kwargs)  # I guess dms doesn't need to be passed up
        ...

which is the normal way to override defaults...

@jklymak
Copy link
Member Author

jklymak commented Apr 23, 2019

I’d agree but the deprecation mechanism causes an exception.

@anntzer
Copy link
Contributor

anntzer commented Apr 23, 2019

OK, we'll make the deprecation machinery better :p

@jklymak
Copy link
Member Author

jklymak commented Apr 23, 2019

Can you copy a property?

@anntzer
Copy link
Contributor

anntzer commented Apr 23, 2019

No, but you can write a class that looks like property but is also correctly triggered on class access.

@jklymak
Copy link
Member Author

jklymak commented Apr 23, 2019

Cartopy needs a .copy operation on update_params. If you can make that work then shouldn’t be a problem. I have a PR in at Cartopy for them to override defaults at init instead of on the attribute but we shouldn’t break Cartopy by changing the type of this public attribute if we can help it

@tacaswell
Copy link
Member

@jklymak #13992 (comment) <- that is an attempt to get what @anntzer is describing to work.

I am 👍 on still deprecating this, just pushing it to 3.2 because it is relatively low-stakes to get done and relatively complex to do correctly.

@anntzer
Copy link
Contributor

anntzer commented Apr 23, 2019

Actually I already tried doing this in #12247 and this runs into #12650; I guess, sure, we could have a deprecated-property-that-warns-on-class-access and a deprecated-property-that-doesn't but I'm not sure it's really worth it, or we could just wait for cartopy to fix this, do the deprecation in the docs and kill this without in-the-code deprecation in 3.3/3.4...

@jklymak jklymak deleted the fix-undeprecate-MaxNLocator-default_params branch April 23, 2019 15:46
@tacaswell
Copy link
Member

did #12247 get reverted? I am confused why that did not work in this case....

@jklymak
Copy link
Member Author

jklymak commented Apr 23, 2019

Cartopy does default_params.copy() and we changed default_params from a dictionary to a property and that then fails.

@anntzer
Copy link
Contributor

anntzer commented Apr 23, 2019

#12247 got reverted in #12653 because warning when accessing on the class really gives you a lot of warnings everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MaxNLocator.default_params deprecation may break Cartopy
4 participants