From 21c28da55da11d337b1a9744929df5a21b06ceac Mon Sep 17 00:00:00 2001 From: MoMo Date: Sat, 14 Feb 2026 05:32:06 +0200 Subject: [PATCH 1/2] Fix violin plot compatibility with NumPy 2.4+ The interpolation parameter was removed in NumPy 2.4.0 and replaced with 'method'. This was causing create_violin() to fail with newer NumPy versions. Added version detection to use the correct parameter based on the installed NumPy version, maintaining backward compatibility with NumPy 1.x while supporting 2.4+. Fixes #5461 --- plotly/figure_factory/_violin.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plotly/figure_factory/_violin.py b/plotly/figure_factory/_violin.py index 55924e69238..17351d8a1b4 100644 --- a/plotly/figure_factory/_violin.py +++ b/plotly/figure_factory/_violin.py @@ -17,9 +17,18 @@ def calc_stats(data): x = np.asarray(data, float) vals_min = np.min(x) vals_max = np.max(x) - q2 = np.percentile(x, 50, interpolation="linear") - q1 = np.percentile(x, 25, interpolation="lower") - q3 = np.percentile(x, 75, interpolation="higher") + + # NumPy 2.0+ renamed 'interpolation' parameter to 'method' + # https://numpy.org/doc/stable/release/2.0.0-notes.html#percentile-and-quantile-methods + numpy_version = tuple(map(int, np.__version__.split('.')[:2])) + if numpy_version >= (2, 0): + q2 = np.percentile(x, 50, method="linear") + q1 = np.percentile(x, 25, method="lower") + q3 = np.percentile(x, 75, method="higher") + else: + q2 = np.percentile(x, 50, interpolation="linear") + q1 = np.percentile(x, 25, interpolation="lower") + q3 = np.percentile(x, 75, interpolation="higher") iqr = q3 - q1 whisker_dist = 1.5 * iqr From 54f65a0778c450de818b1d258418c14b1b105686 Mon Sep 17 00:00:00 2001 From: MoMo Date: Sat, 14 Feb 2026 07:03:29 +0200 Subject: [PATCH 2/2] Apply ruff formatting --- plotly/figure_factory/_violin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plotly/figure_factory/_violin.py b/plotly/figure_factory/_violin.py index 17351d8a1b4..70a0e8f22be 100644 --- a/plotly/figure_factory/_violin.py +++ b/plotly/figure_factory/_violin.py @@ -17,10 +17,10 @@ def calc_stats(data): x = np.asarray(data, float) vals_min = np.min(x) vals_max = np.max(x) - + # NumPy 2.0+ renamed 'interpolation' parameter to 'method' # https://numpy.org/doc/stable/release/2.0.0-notes.html#percentile-and-quantile-methods - numpy_version = tuple(map(int, np.__version__.split('.')[:2])) + numpy_version = tuple(map(int, np.__version__.split(".")[:2])) if numpy_version >= (2, 0): q2 = np.percentile(x, 50, method="linear") q1 = np.percentile(x, 25, method="lower")