Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

Pandas NA type causing serialization errors

In general it looks like the new pandas NA value (see Working with missing data — pandas 1.3.4 documentation) is not handled well by Dash. Here’s a simple example

import dash
from dash import dcc
from dash import html
import plotly.graph_objs as go
import pandas as pd
import numpy as np

app = dash.Dash(__name__)

df = pd.DataFrame({'x':list('aaabbbccc'),'y':np.arange(9)})

##this is handled totally fine
df.loc[5,'x']=np.nan

##this next line will cause a serialization error
df.loc[4,'x']=pd.NA

fig = go.Figure()
fig.add_scatter(x=df['x'],y=df['y'],mode='markers')

app.layout = html.Div(children=[
    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True,port=8060)

This happens for me both in graphs and in datatables, and probably other places too. Here’s another link to the same issue with a datatable How to work with pandas NAType in DataTable

The workaround for me is just not to use the new pandas dtypes, and use np.nan for null everywhere. But it would be nice to take advantage of some of the new pandas functionality (which, while clearly marked “Experimental” is not all that new any more).