Skip to content

Fix create_violin() TypeError with numpy >= 2.0#5538

Open
wavebyrd wants to merge 6035 commits intoplotly:mainfrom
wavebyrd:fix-violin-numpy-2.4-percentile
Open

Fix create_violin() TypeError with numpy >= 2.0#5538
wavebyrd wants to merge 6035 commits intoplotly:mainfrom
wavebyrd:fix-violin-numpy-2.4-percentile

Conversation

@wavebyrd
Copy link

Summary

  • create_violin() calls np.percentile() with the interpolation kwarg, which was renamed to method in numpy 1.22 and fully removed in numpy 2.0. This causes a TypeError on any numpy >= 2.0 install.
  • This patch checks the numpy version at call time and uses the correct kwarg name (method for >= 1.22, interpolation for older releases), keeping backward compatibility intact.

Fixes #5461

Test plan

  • Verify create_violin(data=[1, 2]) no longer raises TypeError on numpy >= 2.0
  • Run the existing test: pytest tests/test_optional/test_figure_factory/test_figure_factory.py::TestViolin::test_violin_fig
  • Confirm nothing breaks on older numpy (< 1.22) where only interpolation is accepted

camdecoster and others added 30 commits August 12, 2025 14:00
Fixes plotly#5253

Signed-off-by: Michał Górny <mgorny@gentoo.org>
Co-authored-by: Emily KL <4672118+emilykl@users.noreply.github.com>
Co-authored-by: Emily KL <4672118+emilykl@users.noreply.github.com>
update Plotly.py version and date
…aults

Copy width/height calculating logic from kaleido
Add missing imports and variable definitions (for main)
Add missing imports and variable definitions
Update CONTRIBUTING.md to include jupyter lab local development instr…
LiamConnors and others added 29 commits February 23, 2026 12:30
…engine-warning

Fix spurious engine deprecation warning in write_image
Co-authored-by: Emily KL <4672118+emilykl@users.noreply.github.com>
Update docs to latest plotly.py version
When px.histogram() is called with no data arguments, the histogram-
specific hover label path inserts a None key into mapping_labels
(because attr_label is None when no column is specified). The hover
template list comprehension then fails with:

    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Skip adding to mapping_labels when attr_label is None, consistent
with how other chart types handle empty invocations.

Fixes plotly#5534
fix: handle empty px.histogram() by skipping None label in hover template
…ed-build-dependencies

Remove not required build dependencies
np.percentile() renamed its `interpolation` kwarg to `method` in
numpy 1.22, and the old name was removed in numpy 2.0. This caused
create_violin() to raise a TypeError on numpy >= 2.0.

Use a version check to pick the right kwarg name so the function
works on both old and new numpy.

Fixes plotly#5461
@wavebyrd wavebyrd force-pushed the fix-violin-numpy-2.4-percentile branch from 132a7e8 to 2d122fd Compare March 13, 2026 21:36
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'