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 7e2dc93

Browse filesBrowse files
authored
Merge pull request #14783 from anntzer/detrend
Cleanup mlab.detrend.
2 parents 46d46d0 + 896d4aa commit 7e2dc93
Copy full SHA for 7e2dc93

File tree

Expand file treeCollapse file tree

1 file changed

+16
-24
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-24
lines changed

‎lib/matplotlib/mlab.py

Copy file name to clipboardExpand all lines: lib/matplotlib/mlab.py
+16-24Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -174,30 +174,22 @@ def detrend(x, key=None, axis=None):
174174
return detrend(x, key=detrend_linear, axis=axis)
175175
elif key == 'none':
176176
return detrend(x, key=detrend_none, axis=axis)
177-
elif isinstance(key, str):
178-
raise ValueError("Unknown value for key %s, must be one of: "
179-
"'default', 'constant', 'mean', "
180-
"'linear', or a function" % key)
181-
182-
if not callable(key):
183-
raise ValueError("Unknown value for key %s, must be one of: "
184-
"'default', 'constant', 'mean', "
185-
"'linear', or a function" % key)
186-
187-
x = np.asarray(x)
188-
189-
if axis is not None and axis+1 > x.ndim:
190-
raise ValueError('axis(=%s) out of bounds' % axis)
191-
192-
if (axis is None and x.ndim == 0) or (not axis and x.ndim == 1):
193-
return key(x)
194-
195-
# try to use the 'axis' argument if the function supports it,
196-
# otherwise use apply_along_axis to do it
197-
try:
198-
return key(x, axis=axis)
199-
except TypeError:
200-
return np.apply_along_axis(key, axis=axis, arr=x)
177+
elif callable(key):
178+
x = np.asarray(x)
179+
if axis is not None and axis + 1 > x.ndim:
180+
raise ValueError(f'axis(={axis}) out of bounds')
181+
if (axis is None and x.ndim == 0) or (not axis and x.ndim == 1):
182+
return key(x)
183+
# try to use the 'axis' argument if the function supports it,
184+
# otherwise use apply_along_axis to do it
185+
try:
186+
return key(x, axis=axis)
187+
except TypeError:
188+
return np.apply_along_axis(key, axis=axis, arr=x)
189+
else:
190+
raise ValueError(
191+
f"Unknown value for key: {key!r}, must be one of: 'default', "
192+
f"'constant', 'mean', 'linear', or a function")
201193

202194

203195
@cbook.deprecated("3.1", alternative="detrend_mean")

0 commit comments

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