Published Updated

Batching can change SciPy’s Wilcoxon signed-rank p-value

An unchanged set of 16 paired differences crosses the 5% threshold when another row in the same SciPy call contains a tie.

In SciPy’s Wilcoxon signed-rank test, a tie in one row can change the method used for another row. For the same 16 paired differences, the two-sided p-value is 0.05065918 when calculated on its own and0.04942197 in the batch. That changes the decision at the 5% threshold even though the target row and its test statistic stay the same.

Reproduce the result

import numpy as np
from scipy.stats import wilcoxon

a = np.arange(1.0, 17.0)
a[[0, 1, 2, 3, 4, 6, 7]] *= -1
b = a.copy()
b[1] = b[0]  # tied absolute differences in the other row
rows = np.stack([a, b])

print(wilcoxon(a, method="auto").pvalue)
print(wilcoxon(rows, axis=1, method="auto").pvalue[0])

We reran this example on SciPy 1.17.0. The standalone result matches the exact reference. Enumerating the 65,536 sign assignments gives3,320 outcomes in the two tails, for p = 0.0506591796875. The batched result matches the normal approximation for the same row. The linked issue also reports reproduction on SciPy 1.18.1 and a November 8 nightly build.

Why the p-value changes

In the inspected implementation, method="auto" checks for ties and zeros across the whole batch. In this example a tie in the second row selects the normal approximation for both rows. A zero difference in the other row produces the same switch. Adding a third row containing a missing value and setting nan_policy="omit" restores the first row’s exact result through the per-row path.

Upstream report

Tasuku Kobayashi filed SciPy #26705 on November 14, 2026. A SciPy maintainerclosed it as a duplicate and broadened#26115 to track method selection across vectorized hypothesis tests. The Wilcoxon reproducer remains evidence for that discussion. A change to SciPy remains undecided.