Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitc301723

Browse files
ksundenmeeseeksmachine
authored andcommitted
Backport PRmatplotlib#26513: Tweak shape repr in _api.check_shape error message.
1 parent275a23f commitc301723

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

‎lib/matplotlib/_api/__init__.py

Lines 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
orany(s!=tandtisnotNonefors,tinzip(data_shape,shape))):
153153
dim_labels=iter(itertools.chain(
154-
'MNLIJKLH',
154+
'NMLKJIH',
155155
(f"D{i}"foriinitertools.count())))
156-
text_shape=", ".join(str(n)
157-
ifnisnotNone
158-
elsenext(dim_labels)
159-
forninshape)
156+
text_shape=", ".join([str(n)ifnisnotNoneelsenext(dim_labels)
157+
forninshape[::-1]][::-1])
160158
iflen(shape)==1:
161159
text_shape+=","
162160

‎lib/matplotlib/tests/test_api.py

Lines 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
deftest_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
withpytest.raises(ValueError,match=error_pattern):
3335
_api.check_shape(target,aardvark=data)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp