Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a965780

Browse filesBrowse files
committed
Use a single more verbose error message
1 parent 0efe198 commit a965780
Copy full SHA for a965780

File tree

Expand file treeCollapse file tree

2 files changed

+11
-7
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-7
lines changed

‎lib/matplotlib/gridspec.py

Copy file name to clipboardExpand all lines: lib/matplotlib/gridspec.py
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,11 @@ def _from_subplot_args(figure, args):
599599
)
600600
i, j = num
601601
else:
602-
if not isinstance(num, Integral):
602+
if not isinstance(num, Integral) or num < 1 or num > rows*cols:
603603
raise ValueError(
604-
f"Subplot specifier must be an integer, not {num!r}")
605-
if num < 1 or num > rows*cols:
606-
raise ValueError(
607-
f"num must be 1 <= num <= {rows*cols}, not {num!r}")
604+
f"num must be an integer with 1 <= num <= {rows*cols}, "
605+
f"not {num!r}"
606+
)
608607
i = j = num
609608
return gs[i-1:j]
610609

‎lib/matplotlib/tests/test_figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_figure.py
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,15 @@ def test_add_subplot_invalid():
236236
with pytest.raises(ValueError,
237237
match='Number of rows must be a positive integer'):
238238
fig.add_subplot(0, 2, 1)
239-
with pytest.raises(ValueError, match='num must be 1 <= num <= 4'):
239+
with pytest.raises(ValueError, match='num must be an integer '
240+
'1 <= num <= 4'):
240241
fig.add_subplot(2, 2, 0)
241-
with pytest.raises(ValueError, match='num must be 1 <= num <= 4'):
242+
with pytest.raises(ValueError, match='num must be an integer '
243+
'1 <= num <= 4'):
242244
fig.add_subplot(2, 2, 5)
245+
with pytest.raises(ValueError, match='num must be an integer '
246+
'1 <= num <= 4'):
247+
fig.add_subplot(2, 2, 0.5)
243248

244249
with pytest.raises(ValueError, match='must be a three-digit integer'):
245250
fig.add_subplot(42)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.