From 17f772d62c58f372a5c993013da349d823347dae Mon Sep 17 00:00:00 2001 From: Tom Hunze Date: Mon, 23 Feb 2026 19:29:01 +0100 Subject: [PATCH] python3Packages.plotly: fix compatibility with numpy 2.4 https://numpy.org/devdocs/release/2.4.0-notes.html#removed-interpolation-parameter-from-quantile-and-percentile-functions https://numpy.org/devdocs/release/2.4.0-notes.html#removed-numpy-in1d Upstream PRs: https://github.com/plotly/plotly.py/pull/5505 https://github.com/plotly/plotly.py/pull/5522 --- .../python-modules/plotly/default.nix | 10 +++++ .../plotly/numpy-2.4-in1d.patch | 38 +++++++++++++++++++ .../numpy-2.4-percentile-interpolation.patch | 17 +++++++++ 3 files changed, 65 insertions(+) create mode 100644 pkgs/development/python-modules/plotly/numpy-2.4-in1d.patch create mode 100644 pkgs/development/python-modules/plotly/numpy-2.4-percentile-interpolation.patch diff --git a/pkgs/development/python-modules/plotly/default.nix b/pkgs/development/python-modules/plotly/default.nix index ec0a17f33fe9..bc76cec9ef89 100644 --- a/pkgs/development/python-modules/plotly/default.nix +++ b/pkgs/development/python-modules/plotly/default.nix @@ -48,6 +48,16 @@ buildPythonPackage rec { hash = "sha256-7rMatpaZvHuNPpiXR5eUHultqNnLER1iW+GR3dwgkyo="; }; + patches = [ + # https://numpy.org/devdocs/release/2.4.0-notes.html#removed-interpolation-parameter-from-quantile-and-percentile-functions + # Upstream PR: https://github.com/plotly/plotly.py/pull/5505 + ./numpy-2.4-percentile-interpolation.patch + + # https://numpy.org/devdocs/release/2.4.0-notes.html#removed-numpy-in1d + # Upstream PR: https://github.com/plotly/plotly.py/pull/5522 + ./numpy-2.4-in1d.patch + ]; + postPatch = '' substituteInPlace pyproject.toml \ --replace-fail '"hatch", ' "" \ diff --git a/pkgs/development/python-modules/plotly/numpy-2.4-in1d.patch b/pkgs/development/python-modules/plotly/numpy-2.4-in1d.patch new file mode 100644 index 000000000000..b6229478184d --- /dev/null +++ b/pkgs/development/python-modules/plotly/numpy-2.4-in1d.patch @@ -0,0 +1,38 @@ +From 9531e7ff00be577560f2cebf6739343646d3c770 Mon Sep 17 00:00:00 2001 +From: Tom Hunze +Date: Mon, 23 Feb 2026 19:21:45 +0100 +Subject: [PATCH] Use `np.isin` instead of `np.in1d` to fix numpy 2.4 test + compatibility + +https://numpy.org/devdocs/release/2.4.0-notes.html#removed-numpy-in1d +--- + tests/test_optional/test_px/test_px.py | 2 +- + tests/test_optional/test_px/test_px_functions.py | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/tests/test_optional/test_px/test_px.py b/tests/test_optional/test_px/test_px.py +index 6c65925a727..a74c4680540 100644 +--- a/tests/test_optional/test_px/test_px.py ++++ b/tests/test_optional/test_px/test_px.py +@@ -36,7 +36,7 @@ def test_custom_data_scatter(backend): + ) + for data in fig.data: + assert np.all( +- np.in1d(data.customdata[:, 1], iris.get_column("petal_width").to_numpy()) ++ np.isin(data.customdata[:, 1], iris.get_column("petal_width").to_numpy()) + ) + # Hover and custom data, no repeated arguments + fig = px.scatter( +diff --git a/tests/test_optional/test_px/test_px_functions.py b/tests/test_optional/test_px/test_px_functions.py +index 0814898f89d..8220ec7a33a 100644 +--- a/tests/test_optional/test_px/test_px_functions.py ++++ b/tests/test_optional/test_px/test_px_functions.py +@@ -307,7 +307,7 @@ def test_sunburst_treemap_with_path_color(constructor): + fig = px.sunburst( + df.to_native(), path=path, color="sectors", color_discrete_map=cmap + ) +- assert np.all(np.in1d(fig.data[0].marker.colors, list(cmap.values()))) ++ assert np.all(np.isin(fig.data[0].marker.colors, list(cmap.values()))) + + # Numerical column in path + df = ( diff --git a/pkgs/development/python-modules/plotly/numpy-2.4-percentile-interpolation.patch b/pkgs/development/python-modules/plotly/numpy-2.4-percentile-interpolation.patch new file mode 100644 index 000000000000..d5d945e473a4 --- /dev/null +++ b/pkgs/development/python-modules/plotly/numpy-2.4-percentile-interpolation.patch @@ -0,0 +1,17 @@ +diff --git a/plotly/figure_factory/_violin.py b/plotly/figure_factory/_violin.py +index 55924e692..e89db0e11 100644 +--- a/plotly/figure_factory/_violin.py ++++ b/plotly/figure_factory/_violin.py +@@ -17,9 +17,9 @@ 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") ++ q2 = np.percentile(x, 50, method="linear") ++ q1 = np.percentile(x, 25, method="lower") ++ q3 = np.percentile(x, 75, method="higher") + iqr = q3 - q1 + whisker_dist = 1.5 * iqr +