Skip to content

ENH: LogLocator: check for correct dimension of subs added #12860

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

Merged
merged 3 commits into from
Aug 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,3 +1260,12 @@ def test_remove_overlap(remove_overlapping_locs, expected_num):
assert len(ax.xaxis.get_minor_ticks()) == expected_num
assert len(ax.xaxis.get_minorticklabels()) == expected_num
assert len(ax.xaxis.get_minorticklines()) == expected_num*2


@pytest.mark.parametrize('sub', [
['hi', 'aardvark'],
np.zeros((2, 2))])
def test_bad_locator_subs(sub):
ll = mticker.LogLocator()
with pytest.raises(ValueError):
ll.subs(sub)
11 changes: 10 additions & 1 deletion lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,16 @@ def subs(self, subs):
cbook._check_in_list(('all', 'auto'), subs=subs)
self._subs = subs
else:
self._subs = np.asarray(subs, dtype=float)
try:
self._subs = np.asarray(subs, dtype=float)
except ValueError as e:
raise ValueError("subs must be None, 'all', 'auto' or "
"a sequence of floats, not "
"{}.".format(subs)) from e
if self._subs.ndim != 1:
raise ValueError("A sequence passed to subs must be "
"1-dimensional, not "
"{}-dimensional.".format(self._subs.ndim))

def __call__(self):
'Return the locations of the ticks'
Expand Down