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

Error out when unsupported kwargs are passed to Scale.#14879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
efiring merged 3 commits intomatplotlib:masterfromanntzer:scalevalidation
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletionsdoc/api/next_api_changes/2019-07-24-AL.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
API changes
```````````

Passing unsupported keyword arguments to `.ScaleBase` and its subclasses
`.LinearScale`, and `.SymLogScale` is deprecated and will raise a `TypeError` in 3.3.

If extra kwargs are pased to `.LogScale`, `TypeError` will now be
raised instead of `ValueError`.
37 changes: 25 additions & 12 deletionslib/matplotlib/scale.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@
NullLocator, LogLocator, AutoLocator, AutoMinorLocator,
SymmetricalLogLocator, LogitLocator)
from matplotlib.transforms import Transform, IdentityTransform
from matplotlib.cbook import warn_deprecated


class ScaleBase:
Expand DownExpand Up@@ -52,6 +53,14 @@ def __init__(self, axis, **kwargs):
be used: a single scale object should be usable by multiple
`~matplotlib.axis.Axis`\es at the same time.
"""
if kwargs:
warn_deprecated(
'3.2.0',
message=(
f"ScaleBase got an unexpected keyword "
f"argument {next(iter(kwargs))!r}. "
'In the future this will raise TypeError')
)

def get_transform(self):
"""
Expand DownExpand Up@@ -143,8 +152,7 @@ def forward(values: array-like) -> array-like
self._forward = forward
self._inverse = inverse
else:
raise ValueError('arguments to FuncTransform must '
'be functions')
raise ValueError('arguments to FuncTransform must be functions')

def transform_non_affine(self, values):
return self._forward(values)
Expand DownExpand Up@@ -382,16 +390,14 @@ def __init__(self, axis, **kwargs):
nonpos = kwargs.pop('nonposy', 'clip')
cbook._check_in_list(['mask', 'clip'], nonposy=nonpos)

if len(kwargs):
raise ValueError(("provided too many kwargs, can only pass "
"{'basex', 'subsx', nonposx'} or "
"{'basey', 'subsy', nonposy'}. You passed ") +
"{!r}".format(kwargs))
if kwargs:
raise TypeError(f"LogScale got an unexpected keyword "
f"argument {next(iter(kwargs))!r}")

if base <= 0 or base == 1:
raise ValueError('The log base cannot be <= 0 or == 1')

self._transform =self.LogTransform(base, nonpos)
self._transform = LogTransform(base, nonpos)
self.subs = subs

@property
Expand DownExpand Up@@ -566,6 +572,16 @@ def __init__(self, axis, **kwargs):
linthresh = kwargs.pop('linthreshy', 2.0)
subs = kwargs.pop('subsy', None)
linscale = kwargs.pop('linscaley', 1.0)
if kwargs:
warn_deprecated(
'3.2.0',
message=(
f"SymmetricalLogScale got an unexpected keyword "
f"argument {next(iter(kwargs))!r}. "
'In the future this will raise TypeError')
)
# raise TypeError(f"SymmetricalLogScale got an unexpected keyword "
# f"argument {next(iter(kwargs))!r}")

if base <= 1.0:
raise ValueError("'basex/basey' must be larger than 1")
Expand All@@ -574,10 +590,7 @@ def __init__(self, axis, **kwargs):
if linscale <= 0.0:
raise ValueError("'linscalex/linthreshy' must be positive")

self._transform = self.SymmetricalLogTransform(base,
linthresh,
linscale)

self._transform = SymmetricalLogTransform(base, linthresh, linscale)
self.base = base
self.linthresh = linthresh
self.linscale = linscale
Expand Down
13 changes: 11 additions & 2 deletionslib/matplotlib/tests/test_scale.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,11 +106,20 @@ def test_logscale_mask():
ax.set(yscale="log")


deftest_extra_kwargs_raise():
deftest_extra_kwargs_raise_or_warn():
fig, ax = plt.subplots()
with pytest.raises(ValueError):

# with pytest.raises(TypeError):
with pytest.warns(MatplotlibDeprecationWarning):
ax.set_yscale('linear', nonpos='mask')

with pytest.raises(TypeError):
ax.set_yscale('log', nonpos='mask')

# with pytest.raises(TypeError):
with pytest.warns(MatplotlibDeprecationWarning):
ax.set_yscale('symlog', nonpos='mask')


def test_logscale_invert_transform():
fig, ax = plt.subplots()
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp