Fix multipletests compatibility with NumPy >= 2.0#449
Merged
Conversation
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>
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
vectorize=Truewith no core dims inmultipletests— which calledstatsmodels_multipletestson each scalar p-value individually — withinput_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 innp.vectorize, causingValueError: setting an array element with a sequence._multipletests_numpyhelper that broadcasts the scalaralphacSidak/alphacBonfoutputs to match the shape of the p-value array (required since all 4 outputs now shareoutput_core_dims=[["s"]])test_multipletests_alphato 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 assertionTest plan
pytest xskillscore/tests/test_stattests.py— 27/27 passedpython -m pytest --doctest-modules xskillscore --ignore xskillscore/tests— 32/32 passed🤖 Generated with Claude Code