plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Plotly express not compatible with pandas NAType/pandas.NA/pd.NA values

Open devmcp opened this issue 4 years ago • 5 comments

Plotly express functions fall over when given dataframes containing pd.NA values. I think these should have the same behaviour as None values.

Example:

# This works
px.scatter(pd.DataFrame([1, 2, 3, None, 5]))

# This results in "TypeError: Object of type NAType is not JSON serializable"
px.scatter(pd.DataFrame([1, 2, 3, None, 5]).convert_dtypes())

devmcp avatar Jun 18 '21 11:06 devmcp

Thanks for pointing that out! We'll try to get it fixed soon :)

nicolaskruchten avatar Jun 18 '21 12:06 nicolaskruchten

Note to self: will need to look at

https://github.com/plotly/plotly.py/blob/b34bd6d2004b2b4c96d114011c82913573e50513/packages/python/plotly/_plotly_utils/utils.py#L168-L178

https://github.com/plotly/plotly.py/blob/b34bd6d2004b2b4c96d114011c82913573e50513/packages/python/plotly/plotly/io/_json.py#L507-L526

nicolaskruchten avatar Jun 18 '21 12:06 nicolaskruchten

This simple addition worked for me when i used px.timeline https://github.com/plotly/plotly.py/pull/3336. Note that I'm a plotly newbie.

stolen from https://github.com/GoogleCloudPlatform/covid-19-open-data/pull/265/files :)

astafan8 avatar Aug 05 '21 15:08 astafan8

#3705 partially fixed this issue. The issue is fixed when Python's json is used, but the problem persists for orjson.

import orjson  # assert that orjson is available

plotly.io.json.config.default_engine = 'json'
px.scatter(pd.DataFrame([1, 2, 3, None, 5]).convert_dtypes()).to_json()  # works
plotly.io.json.config.default_engine = 'auto'  # or `orjson`
px.scatter(pd.DataFrame([1, 2, 3, None, 5]).convert_dtypes()).to_json()  # fails

avm19 avatar Jan 17 '24 21:01 avm19

thank you for taking a look at this @avm19 .

Coding-with-Adam avatar Jan 18 '24 16:01 Coding-with-Adam

Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for a while, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson

gvwilson avatar Jul 11 '24 13:07 gvwilson