Skip to content

Fix Plotly Express mutating lists passed to x or y in wide mode - #5727

Open
cpruijsen wants to merge 1 commit into
plotly:mainfrom
cpruijsen:fix/issue-4117
Open

Fix Plotly Express mutating lists passed to x or y in wide mode#5727
cpruijsen wants to merge 1 commit into
plotly:mainfrom
cpruijsen:fix/issue-4117

Conversation

@cpruijsen

Copy link
Copy Markdown

In wide mode, Plotly Express mutates the list a caller passes as x or y, converting its values to
strings in place. The caller's own variable changes underneath them, which is surprising on its own
and breaks any later use of that list.

build_dataframe in plotly/express/_core.py assigns the argument to args["wide_variable"] and
then replaces entries in it. The copy that would have prevented this was conditional: it only ran when
the value was a pandas Index, so a plain list was aliased rather than copied and the replacement wrote
through to the caller's object.

The copy is now unconditional. list() over a list is a shallow copy, which is all that is needed
here since only the entries are replaced, and the Index case takes the same path it did before.

The test asserts the caller's list is unchanged after the call, which fails on main.

Changelog entry included, per the repo convention.

Fixes #4117

args['wide_variable'] aliased the user-supplied x/y list, and
process_args_into_dataframe replaces its elements with column-name
strings in place. Copy it into a fresh list (this also accepts tuples,
which previously failed on item assignment).

Fixes plotly#4117
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.

Plotly Express constructor: in wide mode, lists passed to x and y params are mutated

1 participant