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

Commit62c9c9c

Browse files
committed
Error out when unsupported kwargs are passed to Scale.
No deprecation period, both because6357245 likewise added the exceptionfor LogScale without deprecation, and because this is by far most likelyto be catching bugs rather than real uses.
1 parent520b5f6 commit62c9c9c

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
API changes
2+
```````````
3+
4+
Passing unsupported keyword arguments to `.ScaleBase` and its subclasses
5+
`.LinearScale`, `.LogScale`, and `.SymLogScale` now raises a TypeError.

‎lib/matplotlib/scale.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ScaleBase:
3939
4040
"""
4141

42-
def__init__(self,axis,**kwargs):
42+
def__init__(self,axis):
4343
r"""
4444
Construct a new scale.
4545
@@ -143,8 +143,7 @@ def forward(values: array-like) -> array-like
143143
self._forward=forward
144144
self._inverse=inverse
145145
else:
146-
raiseValueError('arguments to FuncTransform must '
147-
'be functions')
146+
raiseValueError('arguments to FuncTransform must be functions')
148147

149148
deftransform_non_affine(self,values):
150149
returnself._forward(values)
@@ -382,16 +381,14 @@ def __init__(self, axis, **kwargs):
382381
nonpos=kwargs.pop('nonposy','clip')
383382
cbook._check_in_list(['mask','clip'],nonposy=nonpos)
384383

385-
iflen(kwargs):
386-
raiseValueError(("provided too many kwargs, can only pass "
387-
"{'basex', 'subsx', nonposx'} or "
388-
"{'basey', 'subsy', nonposy'}. You passed ")+
389-
"{!r}".format(kwargs))
384+
ifkwargs:
385+
raiseTypeError(f"LogScale got an unexpected keyword "
386+
f"argument{next(iter(kwargs))!r}")
390387

391388
ifbase<=0orbase==1:
392389
raiseValueError('The log base cannot be <= 0 or == 1')
393390

394-
self._transform=self.LogTransform(base,nonpos)
391+
self._transform=LogTransform(base,nonpos)
395392
self.subs=subs
396393

397394
@property
@@ -566,18 +563,17 @@ def __init__(self, axis, **kwargs):
566563
linthresh=kwargs.pop('linthreshy',2.0)
567564
subs=kwargs.pop('subsy',None)
568565
linscale=kwargs.pop('linscaley',1.0)
569-
566+
ifkwargs:
567+
raiseTypeError(f"SymmetricalLogScale got an unexpected keyword "
568+
f"argument{next(iter(kwargs))!r}")
570569
ifbase<=1.0:
571570
raiseValueError("'basex/basey' must be larger than 1")
572571
iflinthresh<=0.0:
573572
raiseValueError("'linthreshx/linthreshy' must be positive")
574573
iflinscale<=0.0:
575574
raiseValueError("'linscalex/linthreshy' must be positive")
576575

577-
self._transform=self.SymmetricalLogTransform(base,
578-
linthresh,
579-
linscale)
580-
576+
self._transform=SymmetricalLogTransform(base,linthresh,linscale)
581577
self.base=base
582578
self.linthresh=linthresh
583579
self.linscale=linscale

‎lib/matplotlib/tests/test_scale.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,12 @@ def test_logscale_mask():
108108

109109
deftest_extra_kwargs_raise():
110110
fig,ax=plt.subplots()
111+
withpytest.raises(TypeError):
112+
ax.set_yscale('linear',nonpos='mask')
111113
withpytest.raises(ValueError):
112114
ax.set_yscale('log',nonpos='mask')
115+
withpytest.raises(TypeError):
116+
ax.set_yscale('symlog',nonpos='mask')
113117

114118

115119
deftest_logscale_invert_transform():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp