Fix Plotly Express mutating lists passed to x or y in wide mode - #5727
Open
cpruijsen wants to merge 1 commit into
Open
Fix Plotly Express mutating lists passed to x or y in wide mode#5727cpruijsen wants to merge 1 commit into
cpruijsen wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In wide mode, Plotly Express mutates the list a caller passes as
xory, converting its values tostrings 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_dataframeinplotly/express/_core.pyassigns the argument toargs["wide_variable"]andthen 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 neededhere 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