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

Commitd511ab8

Browse files
authored
Merge pull request#14879 from anntzer/scalevalidation
Error out when unsupported kwargs are passed to Scale.
2 parentsb2783ed +c9a2ba6 commitd511ab8

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
API changes
2+
```````````
3+
4+
Passing unsupported keyword arguments to `.ScaleBase` and its subclasses
5+
`.LinearScale`, and `.SymLogScale` is deprecated and will raise a `TypeError` in 3.3.
6+
7+
If extra kwargs are pased to `.LogScale`, `TypeError` will now be
8+
raised instead of `ValueError`.

‎lib/matplotlib/scale.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
NullLocator,LogLocator,AutoLocator,AutoMinorLocator,
2020
SymmetricalLogLocator,LogitLocator)
2121
frommatplotlib.transformsimportTransform,IdentityTransform
22+
frommatplotlib.cbookimportwarn_deprecated
2223

2324

2425
classScaleBase:
@@ -52,6 +53,14 @@ def __init__(self, axis, **kwargs):
5253
be used: a single scale object should be usable by multiple
5354
`~matplotlib.axis.Axis`\es at the same time.
5455
"""
56+
ifkwargs:
57+
warn_deprecated(
58+
'3.2.0',
59+
message=(
60+
f"ScaleBase got an unexpected keyword "
61+
f"argument{next(iter(kwargs))!r}. "
62+
'In the future this will raise TypeError')
63+
)
5564

5665
defget_transform(self):
5766
"""
@@ -143,8 +152,7 @@ def forward(values: array-like) -> array-like
143152
self._forward=forward
144153
self._inverse=inverse
145154
else:
146-
raiseValueError('arguments to FuncTransform must '
147-
'be functions')
155+
raiseValueError('arguments to FuncTransform must be functions')
148156

149157
deftransform_non_affine(self,values):
150158
returnself._forward(values)
@@ -382,16 +390,14 @@ def __init__(self, axis, **kwargs):
382390
nonpos=kwargs.pop('nonposy','clip')
383391
cbook._check_in_list(['mask','clip'],nonposy=nonpos)
384392

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))
393+
ifkwargs:
394+
raiseTypeError(f"LogScale got an unexpected keyword "
395+
f"argument{next(iter(kwargs))!r}")
390396

391397
ifbase<=0orbase==1:
392398
raiseValueError('The log base cannot be <= 0 or == 1')
393399

394-
self._transform=self.LogTransform(base,nonpos)
400+
self._transform=LogTransform(base,nonpos)
395401
self.subs=subs
396402

397403
@property
@@ -566,6 +572,16 @@ def __init__(self, axis, **kwargs):
566572
linthresh=kwargs.pop('linthreshy',2.0)
567573
subs=kwargs.pop('subsy',None)
568574
linscale=kwargs.pop('linscaley',1.0)
575+
ifkwargs:
576+
warn_deprecated(
577+
'3.2.0',
578+
message=(
579+
f"SymmetricalLogScale got an unexpected keyword "
580+
f"argument{next(iter(kwargs))!r}. "
581+
'In the future this will raise TypeError')
582+
)
583+
# raise TypeError(f"SymmetricalLogScale got an unexpected keyword "
584+
# f"argument {next(iter(kwargs))!r}")
569585

570586
ifbase<=1.0:
571587
raiseValueError("'basex/basey' must be larger than 1")
@@ -574,10 +590,7 @@ def __init__(self, axis, **kwargs):
574590
iflinscale<=0.0:
575591
raiseValueError("'linscalex/linthreshy' must be positive")
576592

577-
self._transform=self.SymmetricalLogTransform(base,
578-
linthresh,
579-
linscale)
580-
593+
self._transform=SymmetricalLogTransform(base,linthresh,linscale)
581594
self.base=base
582595
self.linthresh=linthresh
583596
self.linscale=linscale

‎lib/matplotlib/tests/test_scale.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,20 @@ def test_logscale_mask():
106106
ax.set(yscale="log")
107107

108108

109-
deftest_extra_kwargs_raise():
109+
deftest_extra_kwargs_raise_or_warn():
110110
fig,ax=plt.subplots()
111-
withpytest.raises(ValueError):
111+
112+
# with pytest.raises(TypeError):
113+
withpytest.warns(MatplotlibDeprecationWarning):
114+
ax.set_yscale('linear',nonpos='mask')
115+
116+
withpytest.raises(TypeError):
112117
ax.set_yscale('log',nonpos='mask')
113118

119+
# with pytest.raises(TypeError):
120+
withpytest.warns(MatplotlibDeprecationWarning):
121+
ax.set_yscale('symlog',nonpos='mask')
122+
114123

115124
deftest_logscale_invert_transform():
116125
fig,ax=plt.subplots()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp