Skip to content

Use group_by(maintain_order=True) in process_dataframe_hierarchy once narwhals exposes it #5769

Open

Description

@Irahan2

Description

process_dataframe_hierarchy (plotly/express/_core.py), which builds the data for px.sunburst, px.treemap and px.icicle when path is used, adds a temporary row index column, aggregates its minimum per group and sorts each level by it. This is there only to get a deterministic sector order out of group_by, whose row order is not guaranteed for every backend (#5765, #5766).

narwhals is planning to expose maintain_order on group_by (narwhals-dev/narwhals#3309). Once that lands and the minimum supported narwhals version in pyproject.toml includes it, the temporary column, its aggregation and the per-level sort can be dropped in favour of df.group_by(path[i:], drop_null_keys=True, maintain_order=True).

The existing test_sunburst_treemap_with_path_order test covers the behaviour, so it should keep passing after the switch.

Filed as a follow up to #5766, as suggested by @camdecoster in #5765.

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

    P3size: 1task

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions