FIX: create_violin() compatible with NumPy 2.4 percentile API#5470
Open
AJSTYLE-lab wants to merge 2 commits intoplotly:mainfrom
Open
FIX: create_violin() compatible with NumPy 2.4 percentile API#5470AJSTYLE-lab wants to merge 2 commits intoplotly:mainfrom
AJSTYLE-lab wants to merge 2 commits intoplotly:mainfrom
Conversation
Contributor
|
Thanks for the PR. For linting, it can be hard to discern which changes need to be looked at. Could you please rebase this branch to move all linting commits into the first commit, and the bug fix changes into the second? That way we'll be able to review this more quickly. |
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
This PR fixes the
create_violin()function inplotly.figure_factory._violinthat was failing on NumPy 2.4+ due to the removal of theinterpolationargument innp.percentile.Previously, the code used:
python np.percentile(x, q, interpolation="linear")which raises TypeError in NumPy 2.4.
This PR introduces a safe wrapper
_percentile()that usesmethod="linear"for NumPy >= 2.4 and falls back tointerpolation="linear"for older versions.Fix
Added
_percentile()helper function in _violin.py.Updated
calc_stats()to use_percentile()for all percentile calculations (q1, q2, q3).Checklist
Added or updated code to handle NumPy 2.4+ API
Verified that
TestViolin.test_violin_fignow passesRan all unit tests locally (pytest) to confirm no regressions
Committed changes with clear message
PR targets main branch of
plotly/plotly.pyFollowed contribution guidelines
Tests
python -m pytest tests/test_optional/test_figure_factory/test_figure_factory.py::TestViolin::test_violin_figAdditional Notes
This PR only modifies _violin.py; no other files affected.
Code formatting checked with ruff.
Closes [BUG]:
create_violin()failure withnumpy==2.4.0:TypeError: percentile() got an unexpected keyword argument 'interpolation'#5461Screenshot of Testing: