8000 Deprecate hatch patterns with invalid values. · matplotlib/matplotlib@08b03b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 08b03b0

Browse files
committed
Deprecate hatch patterns with invalid values.
1 parent 187e87b commit 08b03b0

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Invalid hatch pattern characters are no longer ignored
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
When specifying hatching patterns, characters that are not recognized will
5+
raise a DeprecationWarning. In the future, this will become a hard error.

lib/matplotlib/collections.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import matplotlib as mpl
1717
from . import (_path, artist, cbook, cm, colors as mcolors, docstring,
18-
lines as mlines, path as mpath, transforms)
18+
hatch as mhatch, lines as mlines, path as mpath, transforms)
1919
import warnings
2020

2121

@@ -522,6 +522,8 @@ def set_hatch(self, hatch):
522522
----------
523523
hatch : {'/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
524524
"""
525+
# Use validate_hatch(list) after deprecation.
526+
mhatch._validate_hatch_pattern(hatch)
525527
self._hatch = hatch
526528
self.stale = True
527529

lib/matplotlib/hatch.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Contains classes for generating hatch patterns."""
22

33
import numpy as np
4+
5+
from matplotlib import cbook
46
from matplotlib.path import Path
57

68

@@ -181,6 +183,20 @@ def __init__(self, hatch, density):
181183
]
182184

183185

186+
def _validate_hatch_pattern(hatch):
187+
valid_hatch_patterns = set(r'-+|/\xXoO.*')
188+
if hatch is not None:
189+
invalids = set(hatch).difference(valid_hatch_patterns)
190+
if invalids:
191+
cbook.warn_deprecated(
192+
'3.4',
193+
message='hatch must consist of a string of '
194+
f'"{"".join(valid_hatch_patterns)}" or None, but '
195+
f'found "{"".join(invalids)}". Passing invalid values '
196+
'is deprecated since %(since)s and will become an '
197+
'error %(removal)s.')
198+
199+
184200
def get_path(hatchpattern, density=6):
185201
"""
186202
Given a hatch specifier, *hatchpattern*, generates Path to render

lib/matplotlib/patches.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import numpy as np
99

1010
import matplotlib as mpl
11-
from . import artist, cbook, colors, docstring, lines as mlines, transforms
11+
from . import (artist, cbook, colors, docstring, hatch as mhatch,
12+
lines as mlines, transforms)
1213
from .bezier import (
1314
NonIntersectingPathException, get_cos_sin, get_intersection,
1415
get_parallels, inside_circle, make_wedged_bezier2,
@@ -513,6 +514,8 @@ def set_hatch(self, hatch):
513514
----------
514515
hatch : {'/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
515516
"""
517+
# Use validate_hatch(list) after deprecation.
518+
mhatch._validate_hatch_pattern(hatch)
516519
self._hatch = hatch
517520
self.stale = True
518521

0 commit comments

Comments
 (0)
0