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 2841c76

Browse filesBrowse files
authored
Merge pull request #26534 from meeseeksmachine/auto-backport-of-pr-26513-on-v3.8.x
Backport PR #26513 on branch v3.8.x (Tweak shape repr in _api.check_shape error message.)
2 parents 5250ffd + c301723 commit 2841c76
Copy full SHA for 2841c76

File tree

2 files changed

+13
-13
lines changed
Filter options

2 files changed

+13
-13
lines changed

‎lib/matplotlib/_api/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_api/__init__.py
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,10 @@ def check_shape(shape, /, **kwargs):
151151
if (len(data_shape) != len(shape)
152152
or any(s != t and t is not None for s, t in zip(data_shape, shape))):
153153
dim_labels = iter(itertools.chain(
154-
'MNLIJKLH',
154+
'NMLKJIH',
155155
(f"D{i}" for i in itertools.count())))
156-
text_shape = ", ".join(str(n)
157-
if n is not None
158-
else next(dim_labels)
159-
for n in shape)
156+
text_shape = ", ".join([str(n) if n is not None else next(dim_labels)
157+
for n in shape[::-1]][::-1])
160158
if len(shape) == 1:
161159
text_shape += ","
162160

‎lib/matplotlib/tests/test_api.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_api.py
+10-8Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@
1717
T = TypeVar('T')
1818

1919

20-
@pytest.mark.parametrize('target,test_shape',
21-
[((None, ), (1, 3)),
22-
((None, 3), (1,)),
23-
((None, 3), (1, 2)),
24-
((1, 5), (1, 9)),
25-
((None, 2, None), (1, 3, 1))
20+
@pytest.mark.parametrize('target,shape_repr,test_shape',
21+
[((None, ), "(N,)", (1, 3)),
22+
((None, 3), "(N, 3)", (1,)),
23+
((None, 3), "(N, 3)", (1, 2)),
24+
((1, 5), "(1, 5)", (1, 9)),
25+
((None, 2, None), "(M, 2, N)", (1, 3, 1))
2626
])
2727
def test_check_shape(target: tuple[int | None, ...],
28+
shape_repr: str,
2829
test_shape: tuple[int, ...]) -> None:
29-
error_pattern = (f"^'aardvark' must be {len(target)}D.*" +
30-
re.escape(f'has shape {test_shape}'))
30+
error_pattern = "^" + re.escape(
31+
f"'aardvark' must be {len(target)}D with shape {shape_repr}, but your input "
32+
f"has shape {test_shape}")
3133
data = np.zeros(test_shape)
3234
with pytest.raises(ValueError, match=error_pattern):
3335
_api.check_shape(target, aardvark=data)

0 commit comments

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