Skip to content

Commit 7a65598

Browse files
committed
TST: Test for acorr function with integer array input
1 parent 4bdae2e commit 7a65598

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/matplotlib/tests/test_axes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,27 @@ def test_acorr(fig_test, fig_ref):
170170
ax_ref.axhline(y=0, xmin=0, xmax=1)
171171

172172

173+
@check_figures_equal(extensions=["png"])
174+
def test_acorr_integers(fig_test, fig_ref):
175+
np.random.seed(19680801)
176+
Nx = 51
177+
x = (np.random.rand(Nx) * 10).cumsum()
178+
x = (np.ceil(x)).astype(np.int64)
179+
maxlags = Nx-1
180+
181+
ax_test = fig_test.subplots()
182+
ax_test.acorr(x, maxlags=maxlags)
183+
184+
ax_ref = fig_ref.subplots()
185+
186+
# Normalized autocorrelation
187+
norm_auto_corr = np.correlate(x, x, mode="full")/np.dot(x, x)
188+
lags = np.arange(-maxlags, maxlags+1)
189+
norm_auto_corr = norm_auto_corr[Nx-1-maxlags:Nx+maxlags]
190+
ax_ref.vlines(lags, [0], norm_auto_corr)
191+
ax_ref.axhline(y=0, xmin=0, xmax=1)
192+
193+
173194
@check_figures_equal(extensions=["png"])
174195
def test_spy(fig_test, fig_ref):
175196
np.random.seed(19680801)

0 commit comments

Comments
 (0)