Skip to content

Commit

Permalink
FIX: Emit DeprecationWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Sep 20, 2017
1 parent 58a789d commit f1be9e7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
38 changes: 23 additions & 15 deletions scipy/signal/__init__.py
Expand Up @@ -292,8 +292,6 @@
"""
from __future__ import division, print_function, absolute_import

import types

from . import sigtools, windows
from .waveforms import *
from ._max_len_seq import max_len_seq
Expand All @@ -317,21 +315,18 @@


# deal with * -> windows.* deprecation
def copy_func(f):
fn = types.FunctionType(f.__code__, f.__globals__, f.__name__,
f.__defaults__, f.__closure__)
fn.__dict__.update(f.__dict__)
return fn


deprecated_windows = ('boxcar', 'triang', 'parzen', 'bohman', 'blackman',
'nuttall', 'blackmanharris', 'flattop', 'bartlett',
'hanning', 'barthann', 'hamming', 'kaiser', 'gaussian',
'general_gaussian', 'chebwin', 'slepian', 'cosine',
'hann', 'exponential', 'tukey')
for name in deprecated_windows:
fun = copy_func(getattr(windows, name))
lines = list(fun.__doc__.splitlines())


def deco(name):
import warnings
f = getattr(windows, name)
# Add deprecation to docstring
lines = list(f.__doc__.splitlines())
for li, line in enumerate(lines):
if line.strip() == 'Parameters':
break
Expand All @@ -341,9 +336,22 @@ def copy_func(f):
lines.insert(li, ('{0}.. warning:: scipy.signal.{1} is deprecated,\n'
'{0} use scipy.signal.windows.{1} instead.\n'
''.format(spacing, name)))
fun.__doc__ = '\n'.join(lines)
locals()[name] = fun
del copy_func, deprecated_windows, name, fun, lines, li, line, spacing, types
doc = '\n'.join(lines)

def wrapped(*args, **kwargs):
warnings.warn('scipy.signal.{0} is deprecated, use '
'scipy.signal.windows.{0} instead'.format(name),
DeprecationWarning)
return f(*args, **kwargs)
wrapped.__name__ = name
wrapped.__doc__ = doc

return wrapped


for name in deprecated_windows:
locals()[name] = deco(name)
del deprecated_windows, name, deco


__all__ = [s for s in dir() if not s.startswith('_')]
Expand Down
7 changes: 4 additions & 3 deletions scipy/signal/tests/test_signaltools.py
Expand Up @@ -21,10 +21,11 @@
from scipy.optimize import fmin
from scipy import signal
from scipy.signal import (
correlate, convolve, convolve2d, fftconvolve, hann, choose_conv_method,
correlate, convolve, convolve2d, fftconvolve, choose_conv_method,
hilbert, hilbert2, lfilter, lfilter_zi, filtfilt, butter, zpk2tf, zpk2sos,
invres, invresz, vectorstrength, lfiltic, tf2sos, sosfilt, sosfiltfilt,
sosfilt_zi, tf2zpk, BadCoefficients)
from scipy.signal.windows import hann
from scipy.signal.signaltools import _filtfilt_gust


Expand Down Expand Up @@ -1721,13 +1722,13 @@ def _test_phaseshift(self, method, zero_phase):
# Sinusoids at 0.8*nyquist, windowed to avoid edge artifacts
freqs = np.array(rates_to) * 0.8 / 2
d = (np.exp(1j * 2 * np.pi * freqs[:, np.newaxis] * t)
* signal.tukey(t.size, 0.1))
* signal.windows.tukey(t.size, 0.1))

for rate_to in rates_to:
q = rate // rate_to
t_to = np.arange(rate_to*t_tot+1) / float(rate_to)
d_tos = (np.exp(1j * 2 * np.pi * freqs[:, np.newaxis] * t_to)
* signal.tukey(t_to.size, 0.1))
* signal.windows.tukey(t_to.size, 0.1))

# Set up downsampling filters, match v0.17 defaults
if method == 'fir':
Expand Down

0 comments on commit f1be9e7

Please sign in to comment.