Skip to content

feat: add maintain_order argument to list.unique#3697

Open
Shaan-alpha wants to merge 1 commit into
narwhals-dev:mainfrom
Shaan-alpha:feat/list-unique-maintain-order
Open

feat: add maintain_order argument to list.unique#3697
Shaan-alpha wants to merge 1 commit into
narwhals-dev:mainfrom
Shaan-alpha:feat/list-unique-maintain-order

Conversation

@Shaan-alpha

Copy link
Copy Markdown

Description

Adds a maintain_order keyword argument to Expr.list.unique and Series.list.unique, matching the Polars API.

  • Polars: forwarded natively (Polars >= 0.20.4, the minimum supported version, already accepts maintain_order on list.unique).
  • Other backends (DuckDB, Spark-like, Ibis): their distinct functions don't guarantee the order of the unique values, so they raise NotImplementedError when maintain_order=True. The default (maintain_order=False) behaviour is unchanged. This mirrors how the project already handles partial support elsewhere (e.g. Ibis raising for descending list.sort).
  • pandas-like / PyArrow already not_implemented list.unique, so they are unaffected.

Happy to extend native order-preserving support to the SQL backends in a follow-up if you'd prefer that over raising.

What type of PR is this? (check all applicable)

  • 💾 Refactor
  • ✨ Feature
  • 🐛 Bug Fix
  • 🔧 Optimization
  • 📝 Documentation
  • ✅ Test
  • 🐳 Other

Related issues

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

Expose Polars' `maintain_order` parameter on `Expr.list.unique` and
`Series.list.unique`. For the Polars backend it is forwarded natively; the
other backends do not guarantee the order of unique values, so they raise
`NotImplementedError` when `maintain_order=True` (mirroring how Ibis handles
descending `list.sort`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add maintain_order argument in {Expr, Series}.list.unique

1 participant