Skip to content

Commit 19c3e9c

Browse files
authored
feat!: remove maintain_order from LazyFrame.unique, as it was never supported (#2247)
* feat!: remove `maintain_order` from `LazyFrame.unique`, as it was never supported * test fixup
1 parent a6361cd commit 19c3e9c

File tree

5 files changed

+8
-21
lines changed

5 files changed

+8
-21
lines changed

narwhals/_dask/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def unique(
217217
self: Self,
218218
subset: list[str] | None,
219219
*,
220-
keep: Literal["any", "none"] = "any",
220+
keep: Literal["any", "none"],
221221
) -> Self:
222222
check_column_exists(self.columns, subset)
223223
native_frame = self._native_frame

narwhals/_dask/group_by.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def agg_dask(
116116
"""
117117
if not exprs:
118118
# No aggregation provided
119-
return df.simple_select(*keys).unique(subset=keys)
119+
return df.simple_select(*keys).unique(subset=keys, keep="any")
120120

121121
all_simple_aggs = True
122122
for expr in exprs:

narwhals/_duckdb/dataframe.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ def collect_schema(self: Self) -> dict[str, DType]:
346346
)
347347
}
348348

349-
def unique(self: Self, subset: Sequence[str] | None, keep: str) -> Self:
349+
def unique(
350+
self: Self, subset: Sequence[str] | None, keep: Literal["any", "none"]
351+
) -> Self:
350352
if subset is not None:
351353
rel = self._native_frame
352354
# Sanitise input

narwhals/dataframe.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,20 +2674,17 @@ def unique(
26742674
subset: str | list[str] | None = None,
26752675
*,
26762676
keep: Literal["any", "none"] = "any",
2677-
maintain_order: bool | None = None,
26782677
) -> Self:
26792678
"""Drop duplicate rows from this LazyFrame.
26802679
26812680
Arguments:
26822681
subset: Column name(s) to consider when identifying duplicate rows.
26832682
If set to `None`, use all columns.
2684-
keep: {'first', 'none'}
2683+
keep: {'any', 'none'}
26852684
Which of the duplicate rows to keep.
26862685
26872686
* 'any': Does not give any guarantee of which row is kept.
2688-
This allows more optimizations.
26892687
* 'none': Don't keep duplicate rows.
2690-
maintain_order: Has no effect and is kept around only for backwards-compatibility.
26912688
26922689
Returns:
26932690
The LazyFrame with unique rows.
@@ -2715,15 +2712,6 @@ def unique(
27152712
f"'any' and 'none' are supported for `keep` in `unique`. Got: {keep}."
27162713
)
27172714
raise ValueError(msg)
2718-
if maintain_order:
2719-
msg = "`maintain_order=True` is not supported for LazyFrame.unique."
2720-
raise ValueError(msg)
2721-
if maintain_order is not None:
2722-
msg = (
2723-
"`maintain_order` has no effect and is only kept around for backwards-compatibility. "
2724-
"You can safely remove this argument."
2725-
)
2726-
warn(message=msg, category=UserWarning, stacklevel=find_stacklevel())
27272715
if isinstance(subset, str):
27282716
subset = [subset]
27292717
return self._from_compliant_dataframe(

tests/frame/unique_test.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,9 @@ def test_unique_none(constructor: Constructor) -> None:
6666
df_raw = constructor(data)
6767
df = nw.from_native(df_raw)
6868

69-
result = df.unique(maintain_order=False).sort("z")
69+
result = df.unique().sort("z")
7070
assert_equal_data(result, data)
7171

72-
if isinstance(df, nw.LazyFrame):
73-
with pytest.raises(ValueError, match="not supported"):
74-
result = df.unique(maintain_order=True).sort("z")
75-
else:
72+
if not isinstance(df, nw.LazyFrame):
7673
result = df.unique(maintain_order=True)
7774
assert_equal_data(result, data)

0 commit comments

Comments
 (0)