8000 Merge pull request #24848 from rcomer/redundant-linestyle-string-hand… · matplotlib/matplotlib@7debecb · GitHub
[go: up one dir, main page]

Skip to content

Commit 7debecb

Browse files
authored
Merge pull request #24848 from rcomer/redundant-linestyle-string-handling
`Collection.set_linestyle`: remove redundant string handling
2 parents bf68676 + ebcb026 commit 7debecb

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

lib/matplotlib/collections.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -608,18 +608,13 @@ def set_linestyle(self, ls):
608608
complete description.
609609
"""
610610
try:
611-
if isinstance(ls, str):
612-
ls = cbook.ls_mapper.get(ls, ls)
613-
dashes = [mlines._get_dash_pattern(ls)]
614-
else:
615-
try:
616-
dashes = [mlines._get_dash_pattern(ls)]
617-
except ValueError:
618-
dashes = [mlines._get_dash_pattern(x) for x in ls]
619-
620-
except ValueError as err:
621-
raise ValueError('Do not know how to convert {!r} to '
622-
'dashes'.format(ls)) from err
611+
dashes = [mlines._get_dash_pattern(ls)]
612+
except ValueError:
613+
try:
614+
dashes = [mlines._get_dash_pattern(x) for x in ls]
615+
except ValueError as err:
616+
emsg = f'Do not know how to convert {ls!r} to dashes'
617+
raise ValueError(emsg) from err
623618

624619
# get the list of raw 'unscaled' dash patterns
625620
self._us_linestyles = dashes

lib/matplotlib/tests/test_collections.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,12 @@ def test_lslw_bcast():
611611
assert (col.get_linewidths() == [1, 2, 3]).all()
612612

613613

614+
def test_set_wrong_linestyle():
615+
c = Collection()
616+
with pytest.raises(ValueError, match="Do not know how to convert 'fuzzy'"):
617+
c.set_linestyle('fuzzy')
618+
619+
614620
@mpl.style.context('default')
615621
def test_capstyle():
616622
col = mcollections.PathCollection([], capstyle='round')

0 commit comments

Comments
 (0)
0