-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
(De-Duplication) linking validate hatch from hatch module #28076
base: main
Are you sure you want to change the base?
Conversation
I think validate_hatch = _validate_hatch_pattern Any fixes for this error? |
rcparams is imported very early in import process so this change adds a circular import (matplotlib/init.py -> rcparams.py -> hatch.py -> matplotlib/init.py). If we want to do this merging, then the cannonical location needs to be in rcparams (as funny as that seems). |
What about going the other direction and doing the validation at run time, which I think is kind of what @anntzer is suggesting in #24797 (comment) b/c it allows for setting third-party hatches in rcParams. |
Ok, so I'm just gonna summarize my understanding of three options:
|
@ShivamPathak99 we discussed this on the call and decision was either do 2. or 3. |
lib/matplotlib/hatch.py
Outdated
@@ -182,6 +182,8 @@ def __init__(self, hatch, density): | |||
def _validate_hatch_pattern(hatch): | |||
valid_hatch_patterns = set(r'-+|/\xXoO.*') | |||
if hatch is not None: | |||
if not isinstance(hatch, str): |
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.
This is an subtle API change that needs to be document as currently
b.set_hatch(('x','x'))
works. The docstring on Patch.set_hatch
is not clear about the type on the input should be.
We do run the hatches through an lrucache so only hashable things work (and it looks like we used as a key in a dictionary before that).
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.
Working on it,
I'm a bit lost on -
We do run the hatches through an lrucache so only hashable things work (and it looks like we used as a key in a dictionary before that).
Could you break it down for me
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.
matplotlib/lib/matplotlib/path.py
Lines 1025 to 1035 in 199c31f
@staticmethod | |
@lru_cache(8) | |
def hatch(hatchpattern, density=6): | |
""" | |
Given a hatch specifier, *hatchpattern*, generates a `Path` that | |
can be used in a repeated hatching pattern. *density* is the | |
number of lines per unit square. | |
""" | |
from matplotlib.hatch import get_path | |
return (get_path(hatchpattern, density) | |
if hatchpattern is not None else None) |
Is part of the code path between Patch.set_hatch
and rendering a hatched patch. The lru_cache
means we will avoid re-computing the hatch path. The lru_cache
is backed by a dictionary (eventually) with the function parameters as the key so only inputs that are hashable can be used.
Sorry for delay, figuring out option 2.
|
hatchModule will call out rcparams for hatch validation
FIXED: ModuleNotFoundError: No module named 'rcsetup'
Have I done it right, some tests are still failing. |
@ShivamPathak99 some of the tests are a bit flakey. I’ve re-run the failed one so let’s see how it goes this time. 🤞 |
Why |
PR summary
issue #24797
Applying the discussed changes in
rcsetup
PR checklist