fix(visualize): use np.trapezoid for AUC/AP, restoring NumPy >=2.4 (#99)#100
Merged
Conversation
np.trapz was renamed to np.trapezoid in NumPy 2.0 and removed in NumPy 2.4, so roc_curve and precision_recall_curve raised AttributeError on NumPy 2.4+ (which CI installs). Resolve np.trapezoid when available and fall back to np.trapz for the declared numpy>=1.15 floor. This broke main CI after #98 merged; it was invisible locally because local NumPy was < 2.4. Closes #99
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR fixes compatibility with NumPy>=2.4 by resolving a shared trapezoidal integration helper at import time (preferring np.trapezoid, falling back to np.trapz) and updating ROC and precision–recall curve metrics to use it, plus documenting the fix in the changelog. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
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
Hotfix:
mainCI went red after #98 because the newtest_precision_recall_curvecoverage test exercisedbraintools.visualize.precision_recall_curve, which (along withroc_curve) callsnp.trapz.np.trapzwas renamed tonp.trapezoidin NumPy 2.0 and removed in NumPy 2.4. CI installsnumpy 2.4.6, so both functions raised:It was invisible locally because local environments had NumPy < 2.4.
Fix
Resolve the integration routine once at import time, preferring
np.trapezoidand falling back tonp.trapzfor the declarednumpy>=1.15floor:Both call sites (
roc_curveAUC,precision_recall_curveAP) now use_trapezoid. Same signature, same semantics.Verification
pytest braintools/visualize/_statistical_extra_test.py braintools/visualize/_statistical_test.py→ 43 passed locally, where_trapezoidresolves tonp.trapezoid(the same path CI's NumPy 2.4.6 takes).Closes #99
Summary by Sourcery
Ensure ROC and precision-recall visualization metrics work with newer NumPy versions by using a compatible trapezoidal integration helper.
Bug Fixes:
roc_curveandprecision_recall_curvewhen running with NumPy >= 2.4 by resolving a compatible trapezoidal integration function at import time.Documentation:
roc_curveandprecision_recall_curvein the changelog.