Skip to content

Fix multipletests compatibility with NumPy >= 2.0#449

Merged
aaronspring merged 2 commits into
mainfrom
fix/multipletests-numpy2-compat
Jun 11, 2026
Merged

Fix multipletests compatibility with NumPy >= 2.0#449
aaronspring merged 2 commits into
mainfrom
fix/multipletests-numpy2-compat

Conversation

@aaronspring

Copy link
Copy Markdown
Collaborator

Summary

  • Replaces vectorize=True with no core dims in multipletests — which called statsmodels_multipletests on each scalar p-value individually — with input_core_dims=[["s"]] so the entire flattened array is passed at once. NumPy 2.0 removed the implicit coercion of 1-element arrays to scalars in np.vectorize, causing ValueError: setting an array element with a sequence.
  • Adds a _multipletests_numpy helper that broadcasts the scalar alphacSidak/alphacBonf outputs to match the shape of the p-value array (required since all 4 outputs now share output_core_dims=[["s"]])
  • Fixes test_multipletests_alpha to use explicit well-controlled p-values instead of random Pearson-r p-values; with proper BH correction, random p-values around 0.19–0.93 are not rejected at any alpha, hiding the test assertion

Test plan

  • pytest xskillscore/tests/test_stattests.py — 27/27 passed
  • python -m pytest --doctest-modules xskillscore --ignore xskillscore/tests — 32/32 passed
  • Full suite: 2794 passed, 3 skipped

🤖 Generated with Claude Code

aaronspring and others added 2 commits June 11, 2026 13:09
Replace per-element vectorize=True approach with a proper core-dims call
that passes the entire flattened p-value array to statsmodels at once.
The old approach relied on numpy.vectorize implicitly coercing 1-element
arrays to scalars, which numpy 2.0 no longer allows.

Also fix test_multipletests_alpha to use explicit p-values with known
small values, since proper BH correction on random Pearson-r p-values
may not reject any tests at either alpha level.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.57%. Comparing base (eccc957) to head (755f8f2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #449      +/-   ##
==========================================
+ Coverage   94.49%   94.57%   +0.08%     
==========================================
  Files          27       27              
  Lines        2836     2841       +5     
==========================================
+ Hits         2680     2687       +7     
+ Misses        156      154       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aaronspring aaronspring requested review from Zeitsperre and removed request for Zeitsperre June 11, 2026 11:15
@aaronspring aaronspring merged commit 16322f1 into main Jun 11, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant