Skip to content

Commit 94bfa1c

Browse files
chore: Simplify polars .list.unique (#2946)
* chore: Simplify polars .list.unique * refactor(typing): Remove unneeded `unique` annotation #2946 (comment) --------- Co-authored-by: dangotbanned <[email protected]>
1 parent 7fb833a commit 94bfa1c

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

narwhals/_polars/expr.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,6 @@ def len(self) -> PolarsExpr:
415415

416416
return self.compliant._with_native(native_result)
417417

418-
def unique(self) -> PolarsExpr:
419-
return self.compliant._with_native(self.native.list.unique())
420-
421418

422419
class PolarsExprStructNamespace(
423420
PolarsExprNamespace, PolarsStructNamespace[PolarsExpr, pl.Expr]

narwhals/_polars/series.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -737,11 +737,6 @@ def len(self) -> PolarsSeries:
737737
ns = self.__narwhals_namespace__()
738738
return self.to_frame().select(ns.col(name).list.len()).get_column(name)
739739

740-
def unique(self) -> PolarsSeries:
741-
name = self.name
742-
ns = self.__narwhals_namespace__()
743-
return self.to_frame().select(ns.col(name).list.unique()).get_column(name)
744-
745740

746741
class PolarsSeriesStructNamespace(
747742
PolarsSeriesNamespace, PolarsStructNamespace[PolarsSeries, pl.Series]

narwhals/_polars/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,13 @@ class PolarsCatNamespace(PolarsAnyNamespace[CompliantT, NativeT_co]):
333333
get_categories: Method[CompliantT]
334334

335335

336-
# NOTE: Use `Protocol` if we **only** have defs to implement
337-
class PolarsListNamespace(
338-
PolarsAnyNamespace[CompliantT_co, NativeT_co], Protocol[CompliantT_co, NativeT_co]
339-
):
336+
class PolarsListNamespace(PolarsAnyNamespace[CompliantT, NativeT_co]):
340337
_accessor: ClassVar[NativeAccessor] = "list"
341338

342-
def len(self) -> CompliantT_co: ...
339+
@abc.abstractmethod
340+
def len(self) -> CompliantT: ...
341+
342+
unique: Method[CompliantT]
343343

344344

345345
class PolarsStructNamespace(PolarsAnyNamespace[CompliantT, NativeT_co]):

0 commit comments

Comments
 (0)