Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion narwhals/_dask/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def unique(
self: Self,
subset: list[str] | None,
*,
keep: Literal["any", "none"] = "any",
keep: Literal["any", "none"],
) -> Self:
check_column_exists(self.columns, subset)
native_frame = self._native_frame
Expand Down
2 changes: 1 addition & 1 deletion narwhals/_dask/group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def agg_dask(
"""
if not exprs:
# No aggregation provided
return df.simple_select(*keys).unique(subset=keys)
return df.simple_select(*keys).unique(subset=keys, keep="any")

all_simple_aggs = True
for expr in exprs:
Expand Down
4 changes: 3 additions & 1 deletion narwhals/_duckdb/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ def collect_schema(self: Self) -> dict[str, DType]:
)
}

def unique(self: Self, subset: Sequence[str] | None, keep: str) -> Self:
def unique(
self: Self, subset: Sequence[str] | None, keep: Literal["any", "none"]
) -> Self:
if subset is not None:
rel = self._native_frame
# Sanitise input
Expand Down
14 changes: 1 addition & 13 deletions narwhals/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2674,20 +2674,17 @@ def unique(
subset: str | list[str] | None = None,
*,
keep: Literal["any", "none"] = "any",
maintain_order: bool | None = None,
) -> Self:
"""Drop duplicate rows from this LazyFrame.

Arguments:
subset: Column name(s) to consider when identifying duplicate rows.
If set to `None`, use all columns.
keep: {'first', 'none'}
keep: {'any', 'none'}
Which of the duplicate rows to keep.

* 'any': Does not give any guarantee of which row is kept.
This allows more optimizations.
* 'none': Don't keep duplicate rows.
maintain_order: Has no effect and is kept around only for backwards-compatibility.

Returns:
The LazyFrame with unique rows.
Expand Down Expand Up @@ -2715,15 +2712,6 @@ def unique(
f"'any' and 'none' are supported for `keep` in `unique`. Got: {keep}."
)
raise ValueError(msg)
if maintain_order:
msg = "`maintain_order=True` is not supported for LazyFrame.unique."
raise ValueError(msg)
if maintain_order is not None:
msg = (
"`maintain_order` has no effect and is only kept around for backwards-compatibility. "
"You can safely remove this argument."
)
warn(message=msg, category=UserWarning, stacklevel=find_stacklevel())
if isinstance(subset, str):
subset = [subset]
return self._from_compliant_dataframe(
Expand Down
7 changes: 2 additions & 5 deletions tests/frame/unique_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ def test_unique_none(constructor: Constructor) -> None:
df_raw = constructor(data)
df = nw.from_native(df_raw)

result = df.unique(maintain_order=False).sort("z")
result = df.unique().sort("z")
assert_equal_data(result, data)

if isinstance(df, nw.LazyFrame):
with pytest.raises(ValueError, match="not supported"):
result = df.unique(maintain_order=True).sort("z")
else:
if not isinstance(df, nw.LazyFrame):
result = df.unique(maintain_order=True)
assert_equal_data(result, data)
Loading