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

Bug: Pie chart category_orders not working with boolean values

Open luigibrancati opened this issue 3 years ago • 0 comments

The option category_orders for pie in Plotly Express does not work when using a bool field in pandas. Here's an example

>>> import pandas as pd
>>> import plotly.express as px
>>> df = pd.DataFrame({'B': [False, True, False]})
>>> df
       B
0  |  False
1  |  True
2  |  False
>>> px.pie(
    df,
    names='B',
    category_orders={'B':[True, False]}
)

The above code breaks with the following error

IndexError: Boolean index has wrong length: 2 instead of 3

Everything works fine when casting the bool field to str or int.

Libraries used:

  • plotly==5.9.0
  • pandas==1.4.3

luigibrancati avatar Jul 27 '22 12:07 luigibrancati