Repository navigation
patch: deepcopy figure fix - #4926
Conversation
| array_ok=", or a list, numpy array or other iterable thereof" | ||
| if self.array_ok | ||
| else "", | ||
| array_ok=( | ||
| ", or a list, numpy array or other iterable thereof" | ||
| if self.array_ok | ||
| else "" | ||
| ), |
There was a problem hiding this comment.
🤔 different black version?
There was a problem hiding this comment.
Oh interesting! Yeah not sure why that's happening but it looks fine?
There was a problem hiding this comment.
Yeah I would not worry too much about this, I just wonder why that's the case 😇
|
I'd love to see a test that fails before these changes! I'm a little concerned that the existing ones didn't catch this |
|
Hey @marthacryan , thanks for getting back to me. Should the example in the issue enough as a test? |
|
Here's a reproducing example that came out of the skimage CI: import numpy as np
import plotly
import plotly.express as px
import plotly.graph_objects as go
plotly.io.renderers.default = "sphinx_gallery_png"
img = np.zeros((50, 50))
fig = px.imshow(img, binary_string=True)
fig.add_trace(
go.Scatter(
x=np.array([[1,2,3],[4,5,6]]),
y=np.array([[1,2,3],[4,5,6]]),
name="1"
)
)
plotly.io.show(fig)Which results in: If you toggle This is plotly 6.0.0rc0 and kaleido 1.0.0rc0. |
|
I am not particularly confident with this part of the code. Minimal example failing in master: import copy
import plotly.express as px
gapminder = px.data.gapminder()
fig = px.line(gapminder, x="year", y="gdpPercap", color="country")
fig_copy = copy.deepcopy(fig)The entire error trace gives some more insights, here what I could figure out (maybe it is trivial, yet it wasn't for me)
Hope it helps |
|
Ah yeah so I can give a little context here. The approach we took for sending base64 encoded arrays was to add the encoding step to the I'm not sure why this isn't failing for other deepcopy tests, but one guess I have is that they aren't numpy/pandas arrays? The base64 encoding only happens for numpy/pandas. |
|
|
||
| fig_copy = copy.deepcopy(fig) | ||
|
|
||
| assert fig_copy is not None |
There was a problem hiding this comment.
This test looks good thank you for doing that! Do you think you could add a simple check that the data did copy correctly? Also, where are the other deepcopy tests you mentioned? Does it make more sense to include this test with those?
There was a problem hiding this comment.
Thanks @marthacryan , what's the best way to assert that the values are the same? is it fig_copy.to_dict() == fig.to_dict()?
Here are few other figure deepcopy's in the test suite:
There was a problem hiding this comment.
I think using fig.to_dict() is fine here. There are other ways to compare them but I just wanted a baseline check that the data is still there
marthacryan
left a comment
There was a problem hiding this comment.
Looks great, thanks @FBruzzesi!
Code PR
Closes #4925 by reverting the changes in 960adb9 to check for
is_none_or_typed_array_spec.Looking for indication if worth adding a test. I see that in few tests a deepcopy of figure is called, thus... I am a bit confused 🙃