diff --git a/narwhals/_arrow/dataframe.py b/narwhals/_arrow/dataframe.py index 16669719e..8576dd2b2 100644 --- a/narwhals/_arrow/dataframe.py +++ b/narwhals/_arrow/dataframe.py @@ -641,7 +641,7 @@ def is_unique(self: Self) -> ArrowSeries: def unique( self: Self, - subset: str | list[str] | None, + subset: list[str] | None, *, keep: Literal["any", "first", "last", "none"], maintain_order: bool, @@ -653,9 +653,6 @@ def unique( import pyarrow.compute as pc df = self._native_frame - - if isinstance(subset, str): - subset = [subset] subset = subset or self.columns if keep in {"any", "first", "last"}: diff --git a/narwhals/_dask/dataframe.py b/narwhals/_dask/dataframe.py index 0e762b1fa..0edf41216 100644 --- a/narwhals/_dask/dataframe.py +++ b/narwhals/_dask/dataframe.py @@ -198,14 +198,13 @@ def head(self: Self, n: int) -> Self: def unique( self: Self, - subset: str | list[str] | None, + subset: list[str] | None, *, keep: Literal["any", "first", "last", "none"] = "any", maintain_order: bool = False, ) -> Self: # The param `maintain_order` is only here for compatibility with the Polars API # and has no effect on the output. - subset = flatten(subset) if subset else None native_frame = self._native_frame if keep == "none": subset = subset or self.columns diff --git a/narwhals/_pandas_like/dataframe.py b/narwhals/_pandas_like/dataframe.py index 6f8706ae4..c10aacec5 100644 --- a/narwhals/_pandas_like/dataframe.py +++ b/narwhals/_pandas_like/dataframe.py @@ -684,7 +684,7 @@ def tail(self, n: int) -> Self: def unique( self: Self, - subset: str | list[str] | None, + subset: list[str] | None, *, keep: Literal["any", "first", "last", "none"] = "any", maintain_order: bool = False, @@ -692,7 +692,6 @@ def unique( # The param `maintain_order` is only here for compatibility with the Polars API # and has no effect on the output. mapped_keep = {"none": False, "any": "first"}.get(keep, keep) - subset = flatten(subset) if subset else None return self._from_native_frame( self._native_frame.drop_duplicates(subset=subset, keep=mapped_keep) ) diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index 2b59dd952..ccdba365e 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -153,6 +153,8 @@ def unique( keep: Literal["any", "first", "last", "none"] = "any", maintain_order: bool = False, ) -> Self: + if isinstance(subset, str): + subset = [subset] return self._from_compliant_dataframe( self._compliant_frame.unique( subset=subset, keep=keep, maintain_order=maintain_order