Skip to content

Conversation

@AJSTYLE-lab
Copy link

@AJSTYLE-lab AJSTYLE-lab commented Jan 15, 2026

Summary

This PR fixes the create_violin() function in plotly.figure_factory._violin that was failing on NumPy 2.4+ due to the removal of the interpolation argument in np.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 uses method="linear" for NumPy >= 2.4 and falls back to interpolation="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_fig now passes

  • Ran all unit tests locally (pytest) to confirm no regressions

  • Committed changes with clear message

  • PR targets main branch of plotly/plotly.py

  • Followed contribution guidelines

Tests

  • Ran locally:
    python -m pytest tests/test_optional/test_figure_factory/test_figure_factory.py::TestViolin::test_violin_fig
  • Test result: ✅ Passed
  • Compatible with all supported NumPy versions (>=1.17, including 2.4).

Additional Notes

Screenshot of Testing:

voilen_issue_screenshot

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