Skip to content

Commit 18c16a0

Browse files
authored
Merge pull request #17715 from anntzer/gserr
MNT: Clarify gridspec error message for non-integer inputs.
2 parents dd8bb2d + 4a62358 commit 18c16a0

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/matplotlib/gridspec.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ def __init__(self, nrows, ncols, height_ratios=None, width_ratios=None):
4545
If not given, all rows will have the same height.
4646
"""
4747
if not isinstance(nrows, Integral) or nrows <= 0:
48-
raise ValueError(f"Number of rows must be > 0, not {nrows}")
48+
raise ValueError(
49+
f"Number of rows must be a positive integer, not {nrows}")
4950
if not isinstance(ncols, Integral) or ncols <= 0:
50-
raise ValueError(f"Number of columns must be > 0, not {ncols}")
51+
raise ValueError(
52+
f"Number of columns must be a positive integer, not {ncols}")
5153
self._nrows, self._ncols = nrows, ncols
5254
self.set_height_ratios(height_ratios)
5355
self.set_width_ratios(width_ratios)

lib/matplotlib/tests/test_figure.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,11 @@ def test_gca():
182182

183183
def test_add_subplot_invalid():
184184
fig = plt.figure()
185-
with pytest.raises(ValueError, match='Number of columns must be > 0'):
185+
with pytest.raises(ValueError,
186+
match='Number of columns must be a positive integer'):
186187
fig.add_subplot(2, 0, 1)
187-
with pytest.raises(ValueError, match='Number of rows must be > 0'):
188+
with pytest.raises(ValueError,
189+
match='Number of rows must be a positive integer'):
188190
fig.add_subplot(0, 2, 1)
189191
with pytest.raises(ValueError, match='num must be 1 <= num <= 4'):
190192
fig.add_subplot(2, 2, 0)

0 commit comments

Comments
 (0)