Skip to content
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

numpy.ndarray serialization behavior #5110

Closed
mun-akkio opened this issue Mar 24, 2025 · 0 comments
Closed

numpy.ndarray serialization behavior #5110

mun-akkio opened this issue Mar 24, 2025 · 0 comments

Comments

@mun-akkio
Copy link

mun-akkio commented Mar 24, 2025

Upgrading to plotly 6.0.1 from 5.24.1, seeing the behavior difference below

import pandas as pd
import plotly
import plotly.express as px
import json

df = pd.DataFrame({"date": ["Apr 2023", "Sep 2023", "Jan 2023", "Dec 2023", "Apr 2023", "Jul 2023", "Jan 2023", "Oct 2023"], "value": [4, 9, 1, 12, 4, 7, 1, 10], "group": ["A", "A", "A", "A", "B", "B", "B", "B"]})
df_grouped = df.groupby(["group", "date"])["value"].sum().reset_index()
fig = px.line(df_grouped, x="date", y="value", color="group")
json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder) 

> '{"data":... "xaxis": "x", "y": {"dtype": "i1", "bdata": "BAwBCQ=="}, "yaxis": "y", "type": "scatter" ...}

fig.to_json()

> '{"data":...,"xaxis":"x","y":{"dtype":"i1","bdata":"BAwBCQ==" ...}

In 5.24.1

json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder) 

> {"data": ..., "xaxis": "x", "y": [4, 12, 1, 9], ...}

fig.to_json()
> '{"data":...,"xaxis":"x","y":[4,12,1,9], ...}

Note that fig.data[0].y is serialized into {"dtype": "i1", "bdata": "BAwBCQ=="} rather than a list. Is that expected behavior with the new version?

@mun-akkio mun-akkio changed the title numpy.ndarray not being serialized numpy.ndarray serialization behavior Mar 24, 2025
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

No branches or pull requests

1 participant