8000 Use `repr` in scatter error message (#24403) · matplotlib/matplotlib@04ce3e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 04ce3e9

Browse files
authored
Use repr in scatter error message (#24403)
* use repr in error message closes #21959 * add test for repr error message * fix formatting * clean up formatting and naming * add `pragma: no cover` * remove import and function name a bit more explicit
1 parent df761c9 commit 04ce3e9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4416,7 +4416,7 @@ def invalid_shape_exception(csize, xsize):
44164416
# severe failure => one may appreciate a verbose feedback.
44174417
raise ValueError(
44184418
f"'c' argument must be a color, a sequence of colors, "
4419-
f"or a sequence of numbers, not {c}") from err
4419+
f"or a sequence of numbers, not {c!r}") from err
44204420
else:
44214421
if len(colors) not in (0, 1, xsize):
44224422
# NB: remember that a single color is also acceptable.

lib/matplotlib/tests/test_axes.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8290,3 +8290,17 @@ def test_extent_units():
82908290
with pytest.raises(ValueError,
82918291
match="set_extent did not consume all of the kwargs"):
82928292
im.set_extent([2, 12, date_first, date_last], clip=False)
8293+
8294+
8295+
def test_scatter_color_repr_error():
8296+
8297+
def get_next_color():
8298+
return 'blue' # pragma: no cover
8299+
msg = (
8300+
r"'c' argument must be a color, a sequence of colors"
8301+
r", or a sequence of numbers, not 'red\\n'"
8302+
)
8303+
with pytest.raises(ValueError, match=msg):
8304+
c = 'red\n'
8305+
mpl.axes.Axes._parse_scatter_color_args(
8306+
c, None, kwargs={}, xsize=2, get_next_color_func=get_next_color)

0 commit comments

Comments
 (0)
0