-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
patch: deepcopy figure fix #4926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
marthacryan
merged 7 commits into
plotly:master
from
FBruzzesi:patch/deepcopy-figure-fix
Dec 9, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d9121c9
patch: deepcopy figure fix
FBruzzesi 484f2df
Merge branch 'master' into patch/deepcopy-figure-fix
FBruzzesi 6808a97
test: add basic deepcopy figure test
FBruzzesi b07c1a3
Merge branch 'master' into patch/deepcopy-figure-fix
FBruzzesi 9c1d326
add equality test, multiple frames and numpy arrays
FBruzzesi 53d5dce
Merge branch 'master' into patch/deepcopy-figure-fix
FBruzzesi 444eca4
Merge branch 'master' into patch/deepcopy-figure-fix
FBruzzesi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
packages/python/plotly/_plotly_utils/tests/validators/test_fig_deepcopy.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import copy | ||
import pytest | ||
import plotly.express as px | ||
|
||
""" | ||
This test is in the validators folder since copy.deepcopy ends up calling | ||
BaseFigure(*args) which hits `validate_coerce`. | ||
|
||
When inputs are dataframes and arrays, then the copied figure is called with | ||
base64 encoded arrays. | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize("return_type", ["pandas", "polars", "pyarrow"]) | ||
@pytest.mark.filterwarnings( | ||
r"ignore:\*scattermapbox\* is deprecated! Use \*scattermap\* instead" | ||
) | ||
def test_deepcopy_dataframe(return_type): | ||
gapminder = px.data.gapminder(return_type=return_type) | ||
fig = px.line(gapminder, x="year", y="gdpPercap", color="country") | ||
fig_copied = copy.deepcopy(fig) | ||
|
||
assert fig_copied.to_dict() == fig.to_dict() | ||
|
||
|
||
@pytest.mark.filterwarnings( | ||
r"ignore:\*scattermapbox\* is deprecated! Use \*scattermap\* instead" | ||
) | ||
def test_deepcopy_array(): | ||
gapminder = px.data.gapminder() | ||
x = gapminder["year"].to_numpy() | ||
y = gapminder["gdpPercap"].to_numpy() | ||
color = gapminder["country"].to_numpy() | ||
|
||
fig = px.line(x=x, y=y, color=color) | ||
fig_copied = copy.deepcopy(fig) | ||
|
||
assert fig_copied.to_dict() == fig.to_dict() |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 different black version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting! Yeah not sure why that's happening but it looks fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I would not worry too much about this, I just wonder why that's the case 😇