Skip to content

Reject unevenly spaced x/y in create_streamline when steps shrink - #5797

Open
raashish1601 wants to merge 2 commits into
plotly:mainfrom
raashish1601:streamline-even-spacing-check
Open

raashish1601 wants to merge 2 commits into
plotly:mainfrom
raashish1601:streamline-even-spacing-check

Conversation

@raashish1601

Copy link
Copy Markdown

create_streamline documents that x and y must be evenly spaced, and validate_streamline is meant to check it. It compares each step with the first step without abs():

if ((x[index + 1] - x[index]) - (x[1] - x[0])) > 0.0001:

so only steps larger than the first one are rejected. A grid whose steps shrink passes:

import plotly.figure_factory as ff
ff.create_streamline([0, 2, 3, 3.5], [0, 1, 2, 3], [[1] * 4] * 4, [[1] * 4] * 4)  # accepted, no error
ff.create_streamline([0, 1, 2, 3], [0, 2, 7, 9], [[1] * 4] * 4, [[1] * 4] * 4)    # PlotlyError, as expected

The streamline integration assumes a uniform grid (it uses x[1] - x[0] and the index position), so such input silently produces misplaced streamlines. This adds abs() to both the x and y checks.

Added test_uneven_x_shrinking_steps and test_uneven_y_shrinking_steps next to the existing test_uneven_x/test_uneven_y. They fail on main and pass with the change, and the rest of TestStreamline passes. ruff format --check (0.11.12) is clean on the changed files.

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.

This branch has not been deployed

No deployments
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.

1 participant