Skip to content

Commit bf9c8df

Browse files
committed
DEP: signal: remove ability to import window functions from signal namespace
1 parent e35edb5 commit bf9c8df

File tree

2 files changed

+3
-77
lines changed

2 files changed

+3
-77
lines changed

scipy/signal/__init__.py

+2-52
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,6 @@
309309
use the classes to create a reusable function instead.
310310
311311
"""
312-
import warnings
313-
import inspect
314312

315313
from . import _sigtools, windows
316314
from ._waveforms import *
@@ -345,58 +343,10 @@
345343
spectral, signaltools, waveforms, wavelets, spline
346344
)
347345

348-
# deal with * -> windows.* doc-only soft-deprecation
349-
deprecated_windows = ('boxcar', 'triang', 'parzen', 'bohman', 'blackman',
350-
'nuttall', 'blackmanharris', 'flattop', 'bartlett',
351-
'barthann', 'hamming', 'kaiser', 'gaussian',
352-
'general_gaussian', 'chebwin', 'cosine',
353-
'hann', 'exponential', 'tukey')
354-
355-
356-
def deco(name):
357-
f = getattr(windows, name)
358-
# Add deprecation to docstring
359-
360-
def wrapped(*args, **kwargs):
361-
warnings.warn(f"Importing {name} from 'scipy.signal' is deprecated "
362-
f"since SciPy 1.1.0 and will raise an error in SciPy 1.13.0. "
363-
f"Please use 'scipy.signal.windows.{name}' or the convenience "
364-
f"function 'scipy.signal.get_window' instead.",
365-
DeprecationWarning, stacklevel=2)
366-
return f(*args, **kwargs)
367-
368-
wrapped.__name__ = name
369-
wrapped.__module__ = 'scipy.signal'
370-
wrapped.__signature__ = inspect.signature(f) # noqa: F821
371-
if hasattr(f, '__qualname__'):
372-
wrapped.__qualname__ = f.__qualname__
373-
374-
if f.__doc__:
375-
lines = f.__doc__.splitlines()
376-
for li, line in enumerate(lines):
377-
if line.strip() == 'Parameters':
378-
break
379-
else:
380-
raise RuntimeError('dev error: badly formatted doc')
381-
spacing = ' ' * line.find('P')
382-
lines.insert(li, ('{0}.. warning:: `scipy.signal.{1}` is deprecated since\n'
383-
'{0} SciPy 1.1.0 and will be removed in 1.13.0\n'
384-
'{0} use `scipy.signal.windows.{1}`'
385-
'instead.\n'.format(spacing, name)))
386-
wrapped.__doc__ = '\n'.join(lines)
387-
388-
return wrapped
389-
390-
391-
for name in deprecated_windows:
392-
locals()[name] = deco(name)
393-
394-
del deprecated_windows, name, deco
395-
396346
__all__ = [
397-
s for s in dir() if not s.startswith("_") and s not in {"warnings", "inspect"}
347+
s for s in dir() if not s.startswith("_")
398348
]
399349

400350
from scipy._lib._testutils import PytestTester
401351
test = PytestTester(__name__)
402-
del PytestTester, inspect
352+
del PytestTester

scipy/signal/tests/test_windows.py

+1-25
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
import pickle
2-
31
import numpy as np
42
from numpy import array
53
from numpy.testing import (assert_array_almost_equal, assert_array_equal,
64
assert_allclose,
75
assert_equal, assert_, assert_array_less,
86
suppress_warnings)
9-
import pytest
107
from pytest import raises as assert_raises
118

129
from scipy.fft import fft
13-
from scipy.signal import windows, get_window, resample, hann as dep_hann
14-
from scipy import signal
10+
from scipy.signal import windows, get_window, resample
1511

1612

1713
window_funcs = [
@@ -39,15 +35,6 @@
3935
('lanczos', ()),
4036
]
4137

42-
@pytest.mark.parametrize(["method", "args"], window_funcs)
43-
def test_deprecated_import(method, args):
44-
if method in ('taylor', 'lanczos', 'dpss'):
45-
pytest.skip("Deprecation test not applicable")
46-
func = getattr(signal, method)
47-
msg = f"Importing {method}"
48-
with pytest.deprecated_call(match=msg):
49-
func(1, *args)
50-
5138

5239
class TestBartHann:
5340

@@ -845,17 +832,6 @@ def test_not_needs_params():
845832
assert_equal(len(win), 7)
846833

847834

848-
def test_deprecation():
849-
if dep_hann.__doc__ is not None: # can be None with `-OO` mode
850-
assert_('signal.hann` is deprecated' in dep_hann.__doc__)
851-
assert_('deprecated' not in windows.hann.__doc__)
852-
853-
854-
def test_deprecated_pickleable():
855-
dep_hann2 = pickle.loads(pickle.dumps(dep_hann))
856-
assert_(dep_hann2 is dep_hann)
857-
858-
859835
def test_symmetric():
860836

861837
for win in [windows.lanczos]:

0 commit comments

Comments
 (0)