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

Skip to content

Replace hardcoded parameter names when creating error bars #23376

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

Closed
wants to merge 4 commits into from

Conversation

wqian94
Copy link
Contributor

@wqian94 wqian94 commented Jun 30, 2022

PR Summary

Use inspect.signature to automagically check whether a kwarg is a
line argument, rather than relying on a hardcoded list. See issue #23375

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

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [✔️] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

wqian94 added 2 commits June 30, 2022 16:45
Use `inspect.signature` to automagically check whether a `kwarg` is a
line argument, rather than relying on a hardcoded list.
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@wqian94 wqian94 marked this pull request as draft June 30, 2022 21:44
@oscargus
Copy link
Member

oscargus commented Jul 4, 2022

I think that although the idea of the PR is good, it is probably quite hard to get through as there is quite a bit of magic going on with the keyword handling, including aliases. However, it is no way intended to discourage you of doing this, it may be possible for some classes, but be prepared for that it can be quite a bit of hassle, closing in to impossible in some cases.

@timhoffm
Copy link
Member

timhoffm commented Jul 4, 2022

@wqian94 thanks for the PR!

I'm hesitant whether the automatism of introspection is useful here. A subset of the parameters should be passed on. While I think this proposal would currently work correctly, it's not a-priori correct that we should not pass any Line2D parameters to the caps. e.g.

  • color should indeed be passed on. The introspection filters it out, and it's only still working because we have special-handling code for that below, which re-introduces the parameter.
  • Other properties like alpha should propagate as well. This works here only because alpha is handled in the Line2D signature via **kwargs. If we would make that explicit in Line2D.__init__, propagation would become broken.

Therefore, it may well be that future code changes will break the correct working of the introspection mechanism. The effect is a change in the visual output (i.e. some properties are not propagated), but no error, which is hard to detect.
OTOH, hard-coding some non-supported parameters is defensive - only remove what you are sure is not working. This may not be complete, but if we pass too much, users will get an error like in #23375, which we can fix explicitly.

Since all parameters will be passed to `LineCollection.set()`, we can
just use that as the primary filter. If there are other keys that should
be excluded, they should be handled separately, such as by overwriting
the value, as is done for some keys.

Notably, `set()` is a kwarg-based key-value updater that uses the
`LineCollection`'s `kwargs` specification to perform the appropriate
updates. This change allows for all of the gatekeeping to be
centralized.
@wqian94
Copy link
Contributor Author

wqian94 commented Jul 5, 2022

Sorry, been away for the weekend.

I'm working on some changes, but it sounds like there isn't much appetite for this, so maybe I'll just keep it as part of a local build instead.

@timhoffm
Copy link
Member

@wqian94 Yes, I think just adding markerfacecoloralt to the hardcoded list. Is the better approach here. Would you be willing to make a PR for that?

@wqian94
Copy link
Contributor Author

wqian94 commented Jul 22, 2022

Sure, I'll submit a separate PR.

@wqian94
Copy link
Contributor Author

wqian94 commented Jul 23, 2022

Replaced with PR #23475

@wqian94 wqian94 closed this Jul 23, 2022
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.

3 participants