Skip to content

Commit 9bd3eb5

Browse files
authored
Merge pull request statsmodels#5958 from bashtage/test-periodogram
MAINT: Deprecate periodogram
2 parents 717808b + 61d1160 commit 9bd3eb5

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

statsmodels/tsa/stattools.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -885,31 +885,37 @@ def ccf(x, y, unbiased=True):
885885
return cvf / (np.std(x) * np.std(y))
886886

887887

888-
def periodogram(X):
888+
def periodogram(x):
889889
"""
890890
Returns the periodogram for the natural frequency of X
891891
892+
.. deprecated::
893+
Use scipy.signal.periodogram instead
894+
892895
Parameters
893896
----------
894-
X : array_like
897+
x : array_like
895898
Array for which the periodogram is desired.
896899
897900
Returns
898901
-------
899902
pgram : array
900-
1./len(X) * np.abs(np.fft.fft(X))**2
901-
903+
1./len(x) * np.abs(np.fft.fft(x))**2
902904
903905
References
904906
----------
905907
.. [*] Brockwell, P.J. and Davis, R.A., 2016. Introduction to time series
906908
and forecasting. Springer.
907909
"""
908-
X = np.asarray(X)
910+
# TODO: Remove after 0.11
911+
import warnings
912+
warnings.warn('periodogram is deprecated and will be removed after 0.11. '
913+
'Use scipy.signal.periodogram instead.', FutureWarning)
914+
x = np.asarray(x)
909915
# if kernel == "bartlett":
910916
# w = 1 - np.arange(M+1.)/M #JP removed integer division
911917

912-
pergr = 1. / len(X) * np.abs(np.fft.fft(X))**2
918+
pergr = 1. / len(x) * np.abs(np.fft.fft(x)) ** 2
913919
pergr[0] = 0. # what are the implications of this?
914920
return pergr
915921

statsmodels/tsa/tests/test_stattools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
coint, acovf, kpss,
2424
arma_order_select_ic, levinson_durbin,
2525
levinson_durbin_pacf, pacf_burg,
26-
innovations_algo, innovations_filter)
26+
innovations_algo, innovations_filter,
27+
periodogram)
2728

2829
DECIMAL_8 = 8
2930
DECIMAL_6 = 6
@@ -911,3 +912,8 @@ def test_adfuller_maxlag_too_large(reset_randomstate):
911912
y = np.random.standard_normal(100)
912913
with pytest.raises(ValueError, match='maxlag must be less than'):
913914
adfuller(y, maxlag=51)
915+
916+
917+
def test_periodogram_future_warning(reset_randomstate):
918+
with pytest.warns(FutureWarning):
919+
periodogram(np.random.standard_normal(100))

0 commit comments

Comments
 (0)