Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb420cd

Browse files
authored
Merge pull request #25892 from meeseeksmachine/auto-backport-of-pr-25832-on-v3.7.x
Backport PR #25832 on branch v3.7.x ([BUG] Prevent under the hood downcasting of values)
2 parents 088fced + 030c3d4 commit eb420cd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,7 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
20802080
correls = np.correlate(x, y, mode="full")
20812081

20822082
if normed:
2083-
correls /= np.sqrt(np.dot(x, x) * np.dot(y, y))
2083+
correls = correls / np.sqrt(np.dot(x, x) * np.dot(y, y))
20842084

20852085
if maxlags is None:
20862086
maxlags = Nx - 1

lib/matplotlib/tests/test_axes.py

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

173173

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

0 commit comments

Comments
 (0)