Skip to content

Fix numpy 2.4.0 compatibility in create_violin()#5483

Open
Mr-Neutr0n wants to merge 1 commit intoplotly:mainfrom
Mr-Neutr0n:fix-numpy-percentile-issue-5461
Open

Fix numpy 2.4.0 compatibility in create_violin()#5483
Mr-Neutr0n wants to merge 1 commit intoplotly:mainfrom
Mr-Neutr0n:fix-numpy-percentile-issue-5461

Conversation

@Mr-Neutr0n
Copy link

Summary

Fixes #5461

The interpolation parameter was deprecated in numpy.percentile() and removed in numpy 2.4.0. It has been replaced with the method parameter which uses the same values.

Problem

create_violin() fails with numpy 2.4.0:

TypeError: percentile() got an unexpected keyword argument 'interpolation'

Solution

Changed all three np.percentile() calls in calc_stats() from using interpolation to method:

  • interpolation="linear"method="linear"
  • interpolation="lower"method="lower"
  • interpolation="higher"method="higher"

Changes

Modified plotly/figure_factory/_violin.py:

# Before
q2 = np.percentile(x, 50, interpolation="linear")
q1 = np.percentile(x, 25, interpolation="lower")
q3 = np.percentile(x, 75, interpolation="higher")

# After
q2 = np.percentile(x, 50, method="linear")
q1 = np.percentile(x, 25, method="lower")
q3 = np.percentile(x, 75, method="higher")

Test plan

import plotly.figure_factory as ff
fig = ff.create_violin(data=[1, 2, 3, 4, 5])
fig.show()  # Should work without error

Or run the existing test:

pytest tests/test_optional/test_figure_factory/test_figure_factory.py::TestViolin::test_violin_fig

🤖 Generated with Claude Code

Fixes plotly#5461

The 'interpolation' parameter was deprecated in numpy.percentile() and
removed in numpy 2.4.0. It has been replaced with the 'method' parameter
which uses the same values.

Changed all three np.percentile() calls in calc_stats() from using
'interpolation' to 'method'.
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.

[BUG]: create_violin() failure with numpy==2.4.0: TypeError: percentile() got an unexpected keyword argument 'interpolation'

1 participant