Skip to content

Commit

Permalink
raise if legend arg has bad type
Browse files Browse the repository at this point in the history
  • Loading branch information
nvaytet committed Aug 7, 2023
1 parent f269631 commit c8b2a37
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/plopp/backends/matplotlib/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ def _make_line(
leg_args = {}
if isinstance(self._canvas._legend, (list, tuple)):
leg_args = {'loc': self._canvas._legend}
elif not isinstance(self._canvas._legend, bool):
raise TypeError(
"Legend must be a bool, tuple, or a list, "
f"not {type(self._canvas._legend)}"
)
self._ax.legend(**leg_args)

def _make_data(self) -> dict:
Expand Down
7 changes: 7 additions & 0 deletions tests/plotting/plot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,10 @@ def test_legend_location():
assert leg2[1] == leg1[1]
assert leg3[1] > leg1[1]
assert leg3[0] == leg1[0]


def test_hide_legend_bad_type():
da1 = data_array(ndim=1)
da2 = da1 * 3.3
with pytest.raises(TypeError, match='Legend must be a bool, tuple, or a list'):
pp.plot({'a': da1, 'b': da2}, legend='False')

0 comments on commit c8b2a37

Please sign in to comment.