Skip to content

Pie chart category_orders not working with boolean values #3826

Description

@luigibrancati

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

Activity

  1. self-assigned this
    on Jul 4, 2024
  2. removed their assignment
    on Aug 2, 2024
  3. changed the title [-]Bug: Pie chart category_orders not working with boolean values[/-] [+]Pie chart category_orders not working with boolean values[/+] on Aug 12, 2024
  4. emilykl commented on Aug 30, 2026

    @emilykl
    Contributor

    This functionality works as expected starting with plotly.py v6.1.0.

    I wasn't able to determine for sure which change resolved the issue, but I suspect it may be a result of the Narwhals migration in #4790.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething broken

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions