Skip to content

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

pkgs/development/python-modules/plotly/default.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ buildPythonPackage rec {
4848
hash = "sha256-7rMatpaZvHuNPpiXR5eUHultqNnLER1iW+GR3dwgkyo=";
4949
};
5050

51+
patches = [
52+
# https://numpy.org/devdocs/release/2.4.0-notes.html#removed-interpolation-parameter-from-quantile-and-percentile-functions
53+
# Upstream PR: https://github.com/plotly/plotly.py/pull/5505
54+
./numpy-2.4-percentile-interpolation.patch
55+
56+
# https://numpy.org/devdocs/release/2.4.0-notes.html#removed-numpy-in1d
57+
# Upstream PR: https://github.com/plotly/plotly.py/pull/5522
58+
./numpy-2.4-in1d.patch
59+
];
60+
5161
postPatch = ''
5262
substituteInPlace pyproject.toml \
5363
--replace-fail '"hatch", ' "" \
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
From 9531e7ff00be577560f2cebf6739343646d3c770 Mon Sep 17 00:00:00 2001
2+
From: Tom Hunze <dev@thunze.de>
3+
Date: Mon, 23 Feb 2026 19:21:45 +0100
4+
Subject: [PATCH] Use `np.isin` instead of `np.in1d` to fix numpy 2.4 test
5+
compatibility
6+
7+
https://numpy.org/devdocs/release/2.4.0-notes.html#removed-numpy-in1d
8+
---
9+
tests/test_optional/test_px/test_px.py | 2 +-
10+
tests/test_optional/test_px/test_px_functions.py | 2 +-
11+
2 files changed, 2 insertions(+), 2 deletions(-)
12+
13+
diff --git a/tests/test_optional/test_px/test_px.py b/tests/test_optional/test_px/test_px.py
14+
index 6c65925a727..a74c4680540 100644
15+
--- a/tests/test_optional/test_px/test_px.py
16+
+++ b/tests/test_optional/test_px/test_px.py
17+
@@ -36,7 +36,7 @@ def test_custom_data_scatter(backend):
18+
)
19+
for data in fig.data:
20+
assert np.all(
21+
- np.in1d(data.customdata[:, 1], iris.get_column("petal_width").to_numpy())
22+
+ np.isin(data.customdata[:, 1], iris.get_column("petal_width").to_numpy())
23+
)
24+
# Hover and custom data, no repeated arguments
25+
fig = px.scatter(
26+
diff --git a/tests/test_optional/test_px/test_px_functions.py b/tests/test_optional/test_px/test_px_functions.py
27+
index 0814898f89d..8220ec7a33a 100644
28+
--- a/tests/test_optional/test_px/test_px_functions.py
29+
+++ b/tests/test_optional/test_px/test_px_functions.py
30+
@@ -307,7 +307,7 @@ def test_sunburst_treemap_with_path_color(constructor):
31+
fig = px.sunburst(
32+
df.to_native(), path=path, color="sectors", color_discrete_map=cmap
33+
)
34+
- assert np.all(np.in1d(fig.data[0].marker.colors, list(cmap.values())))
35+
+ assert np.all(np.isin(fig.data[0].marker.colors, list(cmap.values())))
36+
37+
# Numerical column in path
38+
df = (
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
From 21c28da55da11d337b1a9744929df5a21b06ceac Mon Sep 17 00:00:00 2001
2+
From: MoMo <Mzlwmm748@gmail.com>
3+
Date: Sat, 14 Feb 2026 05:32:06 +0200
4+
Subject: [PATCH] Fix violin plot compatibility with NumPy 2.4+
5+
6+
The interpolation parameter was removed in NumPy 2.4.0 and replaced
7+
with 'method'. This was causing create_violin() to fail with newer
8+
NumPy versions.
9+
10+
Added version detection to use the correct parameter based on the
11+
installed NumPy version, maintaining backward compatibility with
12+
NumPy 1.x while supporting 2.4+.
13+
14+
Fixes #5461
15+
---
16+
plotly/figure_factory/_violin.py | 15 ++++++++++++---
17+
1 file changed, 12 insertions(+), 3 deletions(-)
18+
19+
diff --git a/plotly/figure_factory/_violin.py b/plotly/figure_factory/_violin.py
20+
index 55924e69238..17351d8a1b4 100644
21+
--- a/plotly/figure_factory/_violin.py
22+
+++ b/plotly/figure_factory/_violin.py
23+
@@ -17,9 +17,18 @@ def calc_stats(data):
24+
x = np.asarray(data, float)
25+
vals_min = np.min(x)
26+
vals_max = np.max(x)
27+
- q2 = np.percentile(x, 50, interpolation="linear")
28+
- q1 = np.percentile(x, 25, interpolation="lower")
29+
- q3 = np.percentile(x, 75, interpolation="higher")
30+
+
31+
+ # NumPy 2.0+ renamed 'interpolation' parameter to 'method'
32+
+ # https://numpy.org/doc/stable/release/2.0.0-notes.html#percentile-and-quantile-methods
33+
+ numpy_version = tuple(map(int, np.__version__.split('.')[:2]))
34+
+ if numpy_version >= (2, 0):
35+
+ q2 = np.percentile(x, 50, method="linear")
36+
+ q1 = np.percentile(x, 25, method="lower")
37+
+ q3 = np.percentile(x, 75, method="higher")
38+
+ else:
39+
+ q2 = np.percentile(x, 50, interpolation="linear")
40+
+ q1 = np.percentile(x, 25, interpolation="lower")
41+
+ q3 = np.percentile(x, 75, interpolation="higher")
42+
iqr = q3 - q1
43+
whisker_dist = 1.5 * iqr
44+

0 commit comments

Comments
 (0)