MCPcopy
hub / github.com/pandas-dev/pandas / test_autocorr

Method test_autocorr

pandas/tests/series/methods/test_autocorr.py:5–30  ·  view source on GitHub ↗
(self, datetime_series)

Source from the content-addressed store, hash-verified

3
4class TestAutoCorr:
5 def test_autocorr(self, datetime_series):
6 # Just run the function
7 corr1 = datetime_series.autocorr()
8
9 # Now run it with the lag parameter
10 corr2 = datetime_series.autocorr(lag=1)
11
12 # corr() with lag needs Series of at least length 2
13 if len(datetime_series) <= 2:
14 assert np.isnan(corr1)
15 assert np.isnan(corr2)
16 else:
17 assert corr1 == corr2
18
19 # Choose a random lag between 1 and length of Series - 2
20 # and compare the result with the Series corr() function
21 n = 1 + np.random.default_rng(2).integers(max(1, len(datetime_series) - 2))
22 corr1 = datetime_series.corr(datetime_series.shift(n))
23 corr2 = datetime_series.autocorr(lag=n)
24
25 # corr() with lag needs Series of at least length 2
26 if len(datetime_series) <= 2:
27 assert np.isnan(corr1)
28 assert np.isnan(corr2)
29 else:
30 assert corr1 == corr2

Callers

nothing calls this directly

Calls 4

maxFunction · 0.85
autocorrMethod · 0.80
corrMethod · 0.45
shiftMethod · 0.45

Tested by

no test coverage detected