From 2baad07e7c8d667e9783f679072dd7a55fcd4d62 Mon Sep 17 00:00:00 2001 From: Raashish Aggarwal <94279692+raashish1601@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:12:39 +0530 Subject: [PATCH 1/2] Reject unevenly spaced x/y in create_streamline when steps shrink validate_streamline compared each step with the first one without taking the absolute value, so only steps larger than the first were caught and x such as [0, 2, 3, 3.5] passed as evenly spaced. --- plotly/figure_factory/_streamline.py | 4 ++-- .../test_figure_factory.py | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/plotly/figure_factory/_streamline.py b/plotly/figure_factory/_streamline.py index 55b74c3e7b7..107b49465e9 100644 --- a/plotly/figure_factory/_streamline.py +++ b/plotly/figure_factory/_streamline.py @@ -23,12 +23,12 @@ def validate_streamline(x, y): if np is False: raise ImportError("FigureFactory.create_streamline requires numpy") for index in range(len(x) - 1): - if ((x[index + 1] - x[index]) - (x[1] - x[0])) > 0.0001: + if abs((x[index + 1] - x[index]) - (x[1] - x[0])) > 0.0001: raise exceptions.PlotlyError( "x must be a 1 dimensional, evenly spaced array" ) for index in range(len(y) - 1): - if ((y[index + 1] - y[index]) - (y[1] - y[0])) > 0.0001: + if abs((y[index + 1] - y[index]) - (y[1] - y[0])) > 0.0001: raise exceptions.PlotlyError( "y must be a 1 dimensional, evenly spaced array" ) diff --git a/tests/test_optional/test_figure_factory/test_figure_factory.py b/tests/test_optional/test_figure_factory/test_figure_factory.py index c4dac583204..a6a398df79d 100644 --- a/tests/test_optional/test_figure_factory/test_figure_factory.py +++ b/tests/test_optional/test_figure_factory/test_figure_factory.py @@ -64,6 +64,28 @@ def test_uneven_y(self): } self.assertRaises(PlotlyError, ff.create_streamline, **kwargs) + def test_uneven_x_shrinking_steps(self): + # check for PlotlyError if x steps get smaller than the first one + + kwargs = { + "x": [0, 2, 3, 3.5], + "y": [0, 1, 2, 3], + "u": [[1, 1, 1, 1]] * 4, + "v": [[1, 1, 1, 1]] * 4, + } + self.assertRaises(PlotlyError, ff.create_streamline, **kwargs) + + def test_uneven_y_shrinking_steps(self): + # check for PlotlyError if y steps get smaller than the first one + + kwargs = { + "x": [0, 1, 2, 3], + "y": [0, 2, 3, 3.5], + "u": [[1, 1, 1, 1]] * 4, + "v": [[1, 1, 1, 1]] * 4, + } + self.assertRaises(PlotlyError, ff.create_streamline, **kwargs) + def test_unequal_length_xy(self): # check for PlotlyError if u and v are not the same length From bb044d7cb7c796cd1aeefe1dc1341372dd8f9f97 Mon Sep 17 00:00:00 2001 From: Raashish Aggarwal <94279692+raashish1601@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:13:15 +0530 Subject: [PATCH 2/2] Add changelog entry for create_streamline spacing check --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 346a1459c6a..2de28fe00f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Fix `mpl_to_plotly` crashing on touching bars (such as `plt.hist`) due to floating-point noise producing negative `bargap` values by clamping `bargap` to `[0, 1]` [[#5696](https://github.com/plotly/plotly.py/pull/5696)], with thanks to @robertoffmoura for the contribution! - Export tick label colors to the plotly tickfont in `mpl_to_plotly` [[#5716](https://github.com/plotly/plotly.py/pull/5716)], with thanks to @robertoffmoura for the contribution! - Fix `px.sunburst`, `px.treemap` and `px.icicle` listing sectors in a different order on every run when `path` is used with a Polars DataFrame; sectors now follow their order of first appearance for all dataframe backends [[#5766](https://github.com/plotly/plotly.py/pull/5766)], with thanks to @Irahan2 for the contribution! +- Fix `create_streamline` accepting unevenly spaced `x` or `y` values when later steps are smaller than the first one [[#5797](https://github.com/plotly/plotly.py/pull/5797)] ## [7.1.0] - 2026-09-15