Skip to content

Document that Series.unique order differs from Pandas #11758

Description

@hoxbro

Describe the issue:

Running .unique on a Series differs from the output from pandas. I'm unsure if this is a bug or just a consequence of the move to query planning. If so, it would be nice to mention it in the docstring.

Minimal Complete Verifiable Example:

import dask.dataframe as dd
import pandas as pd

df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], columns=['x', 'y'])
ddf = dd.from_pandas(df, npartitions=2)

ddf.x.unique().compute()  # 3, 1, 5
df.x.unique()  # 1, 3, 5

Anything else we need to know?:

Environment:

  • Dask version: 2025.1.0
  • Python version: 3.12
  • Operating System: Linux
  • Install method (conda, pip, source): conda

Activity

  1. added
    needs triage
    on Feb 18, 2025
  2. maximlt commented on Feb 18, 2025

    @maximlt

    Note I think this is a behavior change, the previous dataframe implementation preserved data ordering as far as I can see. cc holoviz/hvplot#1499

  3. phofl commented on Feb 18, 2025

    @phofl
    Collaborator

    This is expected. We are triggering a shuffle under the hood to avoid overloading a single worker. And a shuffle won't preserve the input order.

    I'll label this as a documentation issue

  4. added
    documentation
    and removed
    needs triage
    on Feb 18, 2025
  5. changed the title [-]`Series.unique` order differs from Pandas[/-] [+]Document that `Series.unique` order differs from Pandas[/+] on Feb 18, 2025
  6. rjzamora commented on Mar 19, 2025

    @rjzamora
    Member

    Just a quick note that the "tree-reduction" version of unique (only good for low-cardinality data) will preserve the original order. E.g.

    ddf.x.unique(split_out=1).compute()  # 1, 3, 5
    df.x.unique()  # 1, 3, 5
  7. added
    needs attention
    on Apr 28, 2025
  8. added a commit that references this issue on Nov 20, 2026
    775d0e1
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

    dataframedocumentationneeds attention

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions