Skip to content

Commit

Permalink
MAINT: Deprecare periodogram
Browse files Browse the repository at this point in the history
Deprecate in favor of tested version in scipy

closes statsmodels#2592
  • Loading branch information
bashtage committed Jul 16, 2019
1 parent 0880f35 commit 61d1160
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
18 changes: 12 additions & 6 deletions statsmodels/tsa/stattools.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,31 +885,37 @@ def ccf(x, y, unbiased=True):
return cvf / (np.std(x) * np.std(y))


def periodogram(X):
def periodogram(x):
"""
Returns the periodogram for the natural frequency of X
.. deprecated::
Use scipy.signal.periodogram instead
Parameters
----------
X : array_like
x : array_like
Array for which the periodogram is desired.
Returns
-------
pgram : array
1./len(X) * np.abs(np.fft.fft(X))**2
1./len(x) * np.abs(np.fft.fft(x))**2
References
----------
.. [*] Brockwell, P.J. and Davis, R.A., 2016. Introduction to time series
and forecasting. Springer.
"""
X = np.asarray(X)
# TODO: Remove after 0.11
import warnings
warnings.warn('periodogram is deprecated and will be removed after 0.11. '
'Use scipy.signal.periodogram instead.', FutureWarning)
x = np.asarray(x)
# if kernel == "bartlett":
# w = 1 - np.arange(M+1.)/M #JP removed integer division

pergr = 1. / len(X) * np.abs(np.fft.fft(X))**2
pergr = 1. / len(x) * np.abs(np.fft.fft(x)) ** 2
pergr[0] = 0. # what are the implications of this?
return pergr

Expand Down
8 changes: 7 additions & 1 deletion statsmodels/tsa/tests/test_stattools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
coint, acovf, kpss,
arma_order_select_ic, levinson_durbin,
levinson_durbin_pacf, pacf_burg,
innovations_algo, innovations_filter)
innovations_algo, innovations_filter,
periodogram)

DECIMAL_8 = 8
DECIMAL_6 = 6
Expand Down Expand Up @@ -911,3 +912,8 @@ def test_adfuller_maxlag_too_large(reset_randomstate):
y = np.random.standard_normal(100)
with pytest.raises(ValueError, match='maxlag must be less than'):
adfuller(y, maxlag=51)


def test_periodogram_future_warning(reset_randomstate):
with pytest.warns(FutureWarning):
periodogram(np.random.standard_normal(100))

0 comments on commit 61d1160

Please sign in to comment.