Skip to content
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

Let as_mpl_selector forward **kwargs to *Selector #392

Merged
merged 10 commits into from
Feb 3, 2022

Conversation

dhomeier
Copy link
Contributor

@dhomeier dhomeier commented Jul 30, 2021

The docstring for the as_mpl_selector methods states that any additional **kwargs can be passed to the respective matplotlib selector instances, but currently they are in fact discarded. This PR passes them through.
In addition I have added the option to override the default rectprops by kwarg – which otherwise might conflict with the argument specified by the user, although it's perhaps to be discussed whether these should always be set by region.visual.

And I think there is a point to have some parameters still set to different defaults from mpl, if not explicitly set by the user, e.g. {'edgecolor': 'black', 'facecolor': 'none'} is certainly the more reasonable default here.

Also todo tests (?); should any/which additional parameters, like drag_from_anywhere, be specifically mentioned in the docstring?

@keflavich
Copy link
Contributor

Yes, let's mention drag_from_anywhere explicitly in the docstring.

@dhomeier dhomeier force-pushed the mpl-selector-kwargs branch 2 times, most recently from 5b061a3 to 8eee8c8 Compare January 7, 2022 20:07
@dhomeier dhomeier marked this pull request as ready for review January 7, 2022 20:15
@dhomeier
Copy link
Contributor Author

dhomeier commented Jan 7, 2022

Marking this as ready for review now, although there could be one or two tests for passing other kwargs added, + the docstring for drag_from_anywhere.
This seems to solve one part of #415; but matplotlib versions < 3.3 that do not have on_select need to be taken care of – either adding our own replacement for the convenience function, or simply skipping those 3 tests.

@dhomeier
Copy link
Contributor Author

dhomeier commented Jan 7, 2022

I should note that the second part of test_mpl_selector_drag is supposed to show that move does not work outside the centre anchor; however it behaves exactly the same with drag_from_anywhere=False as (it is supposed to) with drag_from_anywhere=True. Interactively this works as expected; no idea if then on_select or MouseEvent still behave in some way differently from clicking the real mouse button.

Also not sure if the version check is worth importing packaging.version; it could still relatively easily be done on _mpl_version.split('.'), but it would be nice to have a somewhat more centralised mpl_version control.
Related to this, the new kwargs tests would also need version conditionals, since some of the parameters have been renamed as well in 3.4 or 3.5.

Lastly, the rectprops/props check still allows the user to specify the wrong one; might say this is their responsibility to use the correct form for their matplotlib version, but since passing both kwargs has very weird side effects (e.g. edgecolor becoming facecolor; other parameters getting lost entirely), I am wondering if the user args should get an additional sanity-check.

@dhomeier
Copy link
Contributor Author

dhomeier commented Jan 8, 2022

I've pulled the Matplotlib checks up one level into shapes/utils.py to make an integer MPL_VERSION ([major][minor]) available. Might be useful even at the top level, but I haven't found a good place to put it, and outside shapes there is not much reference to HAS_MATPLOTLIB and I think none to its version.

I've also included a fix to the Mpl intersphinx setup for testing: it seems the base URL has been moved around 3.5 from https://matplotlib.org/ to https://matplotlib.org/stable/ ; if you compare the link to matplotlib.widgets.EllipseSelector in
https://astropy-regions.readthedocs.io/en/stable/api/regions.EllipsePixelRegion.html
to
https://astropy-regions--392.org.readthedocs.build/en/392/api/regions.EllipsePixelRegion.html
the former is pointing to the old URL, being redirected, but losing the section reference in the process.
Seems to work with the changed URL, so this should probably be repaired upstream in astropy docs/conf.py, but we could keep it here as a temporary fix.

Copy link
Contributor

@keflavich keflavich left a comment

Choose a reason for hiding this comment

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

lgtm; I haven't run this locally but it looks good.

regions/shapes/ellipse.py Outdated Show resolved Hide resolved
regions/shapes/rectangle.py Outdated Show resolved Hide resolved
@dhomeier
Copy link
Contributor Author

Changed to AttributeError (have to remember to sync this in the Polygon selector PR as well).
I've reverted the intersphinx path fix, since it is now in Astropy 5.0.1.

@larrybradley
Copy link
Member

Is this ready for a final review?

@dhomeier
Copy link
Contributor Author

dhomeier commented Feb 1, 2022

Is this ready for a final review?

Yes, should now - there was a call from the mpl_selector docs that only worked with mpl dev.

Copy link
Member

@larrybradley larrybradley left a comment

Choose a reason for hiding this comment

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

Thanks, @dhomeier! This looks great. I had just a minor comment about checking the matplotlib version. I'll be glad to stop getting emails about the failing devdeps CI test!

regions/shapes/utils.py Outdated Show resolved Hide resolved
@larrybradley larrybradley self-requested a review February 2, 2022 21:26
@larrybradley
Copy link
Member

Tests are now failing after the updated matplotlib version check.

@larrybradley
Copy link
Member

@dhomeier There are merge conflicts. Can you please rebase?

@dhomeier
Copy link
Contributor Author

dhomeier commented Feb 2, 2022

Doh, was caught right in between by 62eb153 (from the test I thought visual was supposed to not be copied over)!

@larrybradley larrybradley merged commit c99200c into astropy:main Feb 3, 2022
@larrybradley
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants