From d6cb61eb68f9f15e20fcbe86e7fb554a5f002645 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Mon, 6 May 2024 19:50:40 +0200 Subject: [PATCH 1/6] refactor: make polars column inherit from polars cell --- .../tabular/containers/_experimental_polars_column.py | 4 +++- .../containers/_experimental_vectorized_cell.py | 11 ----------- .../containers/_experimental_vectorized_row.py | 6 +++--- 3 files changed, 6 insertions(+), 15 deletions(-) delete mode 100644 src/safeds/data/tabular/containers/_experimental_vectorized_cell.py diff --git a/src/safeds/data/tabular/containers/_experimental_polars_column.py b/src/safeds/data/tabular/containers/_experimental_polars_column.py index db34d863b..b9ae9ca36 100644 --- a/src/safeds/data/tabular/containers/_experimental_polars_column.py +++ b/src/safeds/data/tabular/containers/_experimental_polars_column.py @@ -4,9 +4,11 @@ from collections.abc import Sequence from typing import TypeVar +from safeds.data.tabular.containers import ExperimentalPolarsCell + T = TypeVar("T") # TODO: should not be abstract -class ExperimentalPolarsColumn(ABC, Sequence[T]): +class ExperimentalPolarsColumn(ExperimentalPolarsCell[T], Sequence[T], ABC): pass diff --git a/src/safeds/data/tabular/containers/_experimental_vectorized_cell.py b/src/safeds/data/tabular/containers/_experimental_vectorized_cell.py deleted file mode 100644 index 0a9708d25..000000000 --- a/src/safeds/data/tabular/containers/_experimental_vectorized_cell.py +++ /dev/null @@ -1,11 +0,0 @@ -from ._experimental_polars_cell import ExperimentalPolarsCell -from ._experimental_polars_column import ExperimentalPolarsColumn - - -class _VectorizedCell(ExperimentalPolarsCell): - # ------------------------------------------------------------------------------------------------------------------ - # Dunder methods - # ------------------------------------------------------------------------------------------------------------------ - - def __init__(self, column: ExperimentalPolarsColumn): - self._column: ExperimentalPolarsColumn = column diff --git a/src/safeds/data/tabular/containers/_experimental_vectorized_row.py b/src/safeds/data/tabular/containers/_experimental_vectorized_row.py index 001f7fa71..ff535f77a 100644 --- a/src/safeds/data/tabular/containers/_experimental_vectorized_row.py +++ b/src/safeds/data/tabular/containers/_experimental_vectorized_row.py @@ -2,8 +2,8 @@ from typing import TYPE_CHECKING +from ._experimental_polars_column import ExperimentalPolarsColumn from ._experimental_polars_row import ExperimentalPolarsRow -from ._experimental_vectorized_cell import _VectorizedCell if TYPE_CHECKING: from safeds.data.tabular.typing import ColumnType, Schema @@ -62,7 +62,7 @@ def schema(self) -> Schema: # TODO: rethink return type # Column operations # ------------------------------------------------------------------------------------------------------------------ - def get_value(self, name: str) -> _VectorizedCell: + def get_value(self, name: str) -> ExperimentalPolarsColumn: """ Get the value of the specified column. @@ -76,7 +76,7 @@ def get_value(self, name: str) -> _VectorizedCell: value: The value of the column. """ - return _VectorizedCell(self._table.get_column(name)) + return self._table.get_column(name) def get_column_type(self, name: str) -> ColumnType: # TODO: rethink return type """ From 517d627903a5e15baea01486aa354e2e3fc5f2a8 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Mon, 6 May 2024 22:26:15 +0200 Subject: [PATCH 2/6] feat: basic cell operations --- .../containers/_experimental_polars_cell.py | 151 ++++++++++- .../containers/_experimental_polars_column.py | 235 +++++++++++++++++- .../_experimental_vectorized_row.py | 2 +- 3 files changed, 379 insertions(+), 9 deletions(-) diff --git a/src/safeds/data/tabular/containers/_experimental_polars_cell.py b/src/safeds/data/tabular/containers/_experimental_polars_cell.py index 4b67734a3..962e8a4ec 100644 --- a/src/safeds/data/tabular/containers/_experimental_polars_cell.py +++ b/src/safeds/data/tabular/containers/_experimental_polars_cell.py @@ -1,10 +1,157 @@ from __future__ import annotations -from abc import ABC +from abc import ABC, abstractmethod from typing import Generic, TypeVar T = TypeVar("T") +R = TypeVar("R") class ExperimentalPolarsCell(ABC, Generic[T]): - pass + """A cell is a single value in a table.""" + + # ------------------------------------------------------------------------------------------------------------------ + # Dunder methods + # ------------------------------------------------------------------------------------------------------------------ + + # Comparison --------------------------------------------------------------- + + @abstractmethod + def __eq__(self, other: object) -> ExperimentalPolarsCell[bool]: + ... + + @abstractmethod + def __ge__(self, other) -> ExperimentalPolarsCell[bool]: + ... + + @abstractmethod + def __gt__(self, other) -> ExperimentalPolarsCell[bool]: + ... + + @abstractmethod + def __le__(self, other) -> ExperimentalPolarsCell[bool]: + ... + + @abstractmethod + def __lt__(self, other) -> ExperimentalPolarsCell[bool]: + ... + + # Numeric operators (left operand) ----------------------------------------- + + @abstractmethod + def __add__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __and__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __floordiv__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __matmul__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __mod__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __mul__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __or__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __pow__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __sub__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __truediv__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __xor__(self, other) -> ExperimentalPolarsCell[R]: + ... + + # Numeric operators (right operand) ---------------------------------------- + + @abstractmethod + def __radd__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __rand__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __rfloordiv__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __rmatmul__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __rmod__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __rmul__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __ror__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __rpow__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __rsub__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __rtruediv__(self, other) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __rxor__(self, other) -> ExperimentalPolarsCell[R]: + ... + + # Unary operators ---------------------------------------------------------- + + @abstractmethod + def __abs__(self) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __neg__(self) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __pos__(self) -> ExperimentalPolarsCell[R]: + ... + + @abstractmethod + def __invert__(self) -> ExperimentalPolarsCell[R]: + ... + + # Other -------------------------------------------------------------------- + + @abstractmethod + def __hash__(self) -> int: + ... + + @abstractmethod + def __sizeof__(self) -> int: + ... diff --git a/src/safeds/data/tabular/containers/_experimental_polars_column.py b/src/safeds/data/tabular/containers/_experimental_polars_column.py index b9ae9ca36..c31035f8b 100644 --- a/src/safeds/data/tabular/containers/_experimental_polars_column.py +++ b/src/safeds/data/tabular/containers/_experimental_polars_column.py @@ -1,14 +1,237 @@ from __future__ import annotations -from abc import ABC from collections.abc import Sequence -from typing import TypeVar +from typing import TYPE_CHECKING, TypeVar, overload -from safeds.data.tabular.containers import ExperimentalPolarsCell +from ._experimental_polars_cell import ExperimentalPolarsCell + +if TYPE_CHECKING: + from polars import Series T = TypeVar("T") +R = TypeVar("R") + + +class ExperimentalPolarsColumn(ExperimentalPolarsCell[T], Sequence[T]): + """ + A column is a named, one-dimensional collection of homogeneous values. + + Parameters + ---------- + name: + The name of the column. + data: + The data. If None, an empty column is created. + + Examples + -------- + >>> from safeds.data.tabular.containers import Column + >>> column = Column("test", [1, 2, 3]) + """ + + # ------------------------------------------------------------------------------------------------------------------ + # Import + # ------------------------------------------------------------------------------------------------------------------ + + @staticmethod + def _from_polars_series(data: Series) -> ExperimentalPolarsColumn: + result = object.__new__(ExperimentalPolarsColumn) + result._series = data + return result + + # ------------------------------------------------------------------------------------------------------------------ + # Dunder methods + # ------------------------------------------------------------------------------------------------------------------ + + def __init__(self, name: str, data: Sequence[T] | None = None) -> None: + import polars as pl + + if data is None: + data = [] + + self._series: pl.Series = pl.Series(name, data) + + # Collection --------------------------------------------------------------- + + @overload + def __getitem__(self, index: int) -> T: ... + + @overload + def __getitem__(self, index: slice) -> T: ... + + def __getitem__(self, index: int | slice) -> T: + return self._series.__getitem__(index) + + def __len__(self) -> int: + return self._series.__len__() + + # Comparison --------------------------------------------------------------- + + def __eq__(self, other: object) -> ExperimentalPolarsCell[bool]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__eq__(other), + ) + + def __ge__(self, other) -> ExperimentalPolarsCell[bool]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__ge__(other), + ) + + def __gt__(self, other) -> ExperimentalPolarsCell[bool]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__gt__(other), + ) + + def __le__(self, other) -> ExperimentalPolarsCell[bool]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__le__(other), + ) + + def __lt__(self, other) -> ExperimentalPolarsCell[bool]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__lt__(other), + ) + + # Numeric operators (left operand) ----------------------------------------- + + def __add__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__add__(other), + ) + + def __and__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__and__(other), + ) + + def __floordiv__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__floordiv__(other), + ) + + def __matmul__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__matmul__(other), + ) + + def __mod__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__mod__(other), + ) + + def __mul__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__mul__(other), + ) + + def __or__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__or__(other), + ) + + def __pow__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__pow__(other), + ) + + def __sub__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__sub__(other), + ) + + def __truediv__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__truediv__(other), + ) + + def __xor__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__xor__(other), + ) + + # Numeric operators (right operand) ---------------------------------------- + + def __radd__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__radd__(other), + ) + + def __rand__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__rand__(other), + ) + + def __rfloordiv__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__rfloordiv__(other), + ) + + def __rmatmul__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__rmatmul__(other), + ) + + def __rmod__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__rmod__(other), + ) + + def __rmul__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__rmul__(other), + ) + + def __ror__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__ror__(other), + ) + + def __rpow__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__rpow__(other), + ) + + def __rsub__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__rsub__(other), + ) + + def __rtruediv__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__rtruediv__(other), + ) + + def __rxor__(self, other) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__rxor__(other), + ) + + # Unary operators ---------------------------------------------------------- + + def __abs__(self) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__abs__(), + ) + + def __neg__(self) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__neg__(), + ) + + def __pos__(self) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__pos__(), + ) + + def __invert__(self) -> ExperimentalPolarsCell[R]: + return ExperimentalPolarsColumn._from_polars_series( + self._series.__invert__(), + ) + + # Other -------------------------------------------------------------------- + def __hash__(self) -> int: + raise NotImplementedError -# TODO: should not be abstract -class ExperimentalPolarsColumn(ExperimentalPolarsCell[T], Sequence[T], ABC): - pass + def __sizeof__(self) -> int: + raise NotImplementedError diff --git a/src/safeds/data/tabular/containers/_experimental_vectorized_row.py b/src/safeds/data/tabular/containers/_experimental_vectorized_row.py index ff535f77a..71191b447 100644 --- a/src/safeds/data/tabular/containers/_experimental_vectorized_row.py +++ b/src/safeds/data/tabular/containers/_experimental_vectorized_row.py @@ -2,12 +2,12 @@ from typing import TYPE_CHECKING -from ._experimental_polars_column import ExperimentalPolarsColumn from ._experimental_polars_row import ExperimentalPolarsRow if TYPE_CHECKING: from safeds.data.tabular.typing import ColumnType, Schema + from ._experimental_polars_column import ExperimentalPolarsColumn from ._experimental_polars_table import ExperimentalPolarsTable From 66f9a8cbf9461c3b584a3d0d71ab4320e809a4e7 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Mon, 6 May 2024 23:33:01 +0200 Subject: [PATCH 3/6] refactor: refine types --- .../containers/_experimental_lazy_column.py | 10 + .../containers/_experimental_polars_cell.py | 77 +++-- .../containers/_experimental_polars_column.py | 280 ++++++++---------- 3 files changed, 171 insertions(+), 196 deletions(-) create mode 100644 src/safeds/data/tabular/containers/_experimental_lazy_column.py diff --git a/src/safeds/data/tabular/containers/_experimental_lazy_column.py b/src/safeds/data/tabular/containers/_experimental_lazy_column.py new file mode 100644 index 000000000..473ecfe64 --- /dev/null +++ b/src/safeds/data/tabular/containers/_experimental_lazy_column.py @@ -0,0 +1,10 @@ +# TODO: polars expressions get optimized first, before being applied. For further performance improvements (if needed), +# we should mirror this when transitioning from a vectorized row to a cell. + +from abc import ABC + +from safeds.data.tabular.containers import ExperimentalPolarsCell + + +class _LazyColumn(ExperimentalPolarsCell, ABC): + pass diff --git a/src/safeds/data/tabular/containers/_experimental_polars_cell.py b/src/safeds/data/tabular/containers/_experimental_polars_cell.py index 962e8a4ec..81c2cea7c 100644 --- a/src/safeds/data/tabular/containers/_experimental_polars_cell.py +++ b/src/safeds/data/tabular/containers/_experimental_polars_cell.py @@ -1,9 +1,10 @@ from __future__ import annotations from abc import ABC, abstractmethod -from typing import Generic, TypeVar +from typing import Any, Generic, TypeVar T = TypeVar("T") +P = TypeVar("P") R = TypeVar("R") @@ -14,136 +15,126 @@ class ExperimentalPolarsCell(ABC, Generic[T]): # Dunder methods # ------------------------------------------------------------------------------------------------------------------ - # Comparison --------------------------------------------------------------- + # "Boolean" operators (actually bitwise) ----------------------------------- @abstractmethod - def __eq__(self, other: object) -> ExperimentalPolarsCell[bool]: + def __invert__(self) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __ge__(self, other) -> ExperimentalPolarsCell[bool]: + def __and__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __gt__(self, other) -> ExperimentalPolarsCell[bool]: + def __rand__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __le__(self, other) -> ExperimentalPolarsCell[bool]: + def __or__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __lt__(self, other) -> ExperimentalPolarsCell[bool]: + def __ror__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ... - # Numeric operators (left operand) ----------------------------------------- - @abstractmethod - def __add__(self, other) -> ExperimentalPolarsCell[R]: + def __xor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __and__(self, other) -> ExperimentalPolarsCell[R]: + def __rxor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ... - @abstractmethod - def __floordiv__(self, other) -> ExperimentalPolarsCell[R]: - ... + # Comparison --------------------------------------------------------------- @abstractmethod - def __matmul__(self, other) -> ExperimentalPolarsCell[R]: + def __eq__(self, other: object) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __mod__(self, other) -> ExperimentalPolarsCell[R]: + def __ge__(self, other: Any) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __mul__(self, other) -> ExperimentalPolarsCell[R]: + def __gt__(self, other: Any) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __or__(self, other) -> ExperimentalPolarsCell[R]: + def __le__(self, other: Any) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __pow__(self, other) -> ExperimentalPolarsCell[R]: + def __lt__(self, other: Any) -> ExperimentalPolarsCell[bool]: ... - @abstractmethod - def __sub__(self, other) -> ExperimentalPolarsCell[R]: - ... + # Numeric operators -------------------------------------------------------- @abstractmethod - def __truediv__(self, other) -> ExperimentalPolarsCell[R]: + def __abs__(self) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __xor__(self, other) -> ExperimentalPolarsCell[R]: + def __neg__(self) -> ExperimentalPolarsCell[R]: ... - # Numeric operators (right operand) ---------------------------------------- - @abstractmethod - def __radd__(self, other) -> ExperimentalPolarsCell[R]: + def __pos__(self) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rand__(self, other) -> ExperimentalPolarsCell[R]: + def __add__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rfloordiv__(self, other) -> ExperimentalPolarsCell[R]: + def __radd__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rmatmul__(self, other) -> ExperimentalPolarsCell[R]: + def __floordiv__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rmod__(self, other) -> ExperimentalPolarsCell[R]: + def __rfloordiv__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rmul__(self, other) -> ExperimentalPolarsCell[R]: + def __mod__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __ror__(self, other) -> ExperimentalPolarsCell[R]: + def __rmod__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rpow__(self, other) -> ExperimentalPolarsCell[R]: + def __mul__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rsub__(self, other) -> ExperimentalPolarsCell[R]: + def __rmul__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rtruediv__(self, other) -> ExperimentalPolarsCell[R]: + def __pow__(self, other: float | ExperimentalPolarsCell[P]) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rxor__(self, other) -> ExperimentalPolarsCell[R]: + def __rpow__(self, other: float | ExperimentalPolarsCell[P]) -> ExperimentalPolarsCell[R]: ... - # Unary operators ---------------------------------------------------------- - @abstractmethod - def __abs__(self) -> ExperimentalPolarsCell[R]: + def __sub__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __neg__(self) -> ExperimentalPolarsCell[R]: + def __rsub__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __pos__(self) -> ExperimentalPolarsCell[R]: + def __truediv__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __invert__(self) -> ExperimentalPolarsCell[R]: + def __rtruediv__(self, other: Any) -> ExperimentalPolarsCell[R]: ... # Other -------------------------------------------------------------------- diff --git a/src/safeds/data/tabular/containers/_experimental_polars_column.py b/src/safeds/data/tabular/containers/_experimental_polars_column.py index c31035f8b..e688933f9 100644 --- a/src/safeds/data/tabular/containers/_experimental_polars_column.py +++ b/src/safeds/data/tabular/containers/_experimental_polars_column.py @@ -1,7 +1,7 @@ from __future__ import annotations from collections.abc import Sequence -from typing import TYPE_CHECKING, TypeVar, overload +from typing import TYPE_CHECKING, Any, TypeVar, overload from ._experimental_polars_cell import ExperimentalPolarsCell @@ -9,6 +9,7 @@ from polars import Series T = TypeVar("T") +P = TypeVar("P") R = TypeVar("R") @@ -51,6 +52,35 @@ def __init__(self, name: str, data: Sequence[T] | None = None) -> None: self._series: pl.Series = pl.Series(name, data) + # "Boolean" operators (actually bitwise) ----------------------------------- + + def __invert__(self) -> ExperimentalPolarsCell[bool]: + return _wrap(self._series.__invert__().cast(bool)) + + def __and__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: + other = _unwrap(other) + return _wrap(self._series.__and__(other).cast(bool)) + + def __rand__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: + other = _unwrap(other) + return _wrap(self._series.__rand__(other).cast(bool)) + + def __or__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: + other = _unwrap(other) + return _wrap(self._series.__or__(other).cast(bool)) + + def __ror__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: + other = _unwrap(other) + return _wrap(self._series.__ror__(other).cast(bool)) + + def __xor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: + other = _unwrap(other) + return _wrap(self._series.__xor__(other).cast(bool)) + + def __rxor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: + other = _unwrap(other) + return _wrap(self._series.__rxor__(other).cast(bool)) + # Collection --------------------------------------------------------------- @overload @@ -68,165 +98,99 @@ def __len__(self) -> int: # Comparison --------------------------------------------------------------- def __eq__(self, other: object) -> ExperimentalPolarsCell[bool]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__eq__(other), - ) - - def __ge__(self, other) -> ExperimentalPolarsCell[bool]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__ge__(other), - ) - - def __gt__(self, other) -> ExperimentalPolarsCell[bool]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__gt__(other), - ) - - def __le__(self, other) -> ExperimentalPolarsCell[bool]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__le__(other), - ) - - def __lt__(self, other) -> ExperimentalPolarsCell[bool]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__lt__(other), - ) - - # Numeric operators (left operand) ----------------------------------------- - - def __add__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__add__(other), - ) - - def __and__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__and__(other), - ) - - def __floordiv__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__floordiv__(other), - ) - - def __matmul__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__matmul__(other), - ) - - def __mod__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__mod__(other), - ) - - def __mul__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__mul__(other), - ) - - def __or__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__or__(other), - ) - - def __pow__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__pow__(other), - ) - - def __sub__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__sub__(other), - ) - - def __truediv__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__truediv__(other), - ) - - def __xor__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__xor__(other), - ) - - # Numeric operators (right operand) ---------------------------------------- - - def __radd__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__radd__(other), - ) - - def __rand__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__rand__(other), - ) - - def __rfloordiv__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__rfloordiv__(other), - ) - - def __rmatmul__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__rmatmul__(other), - ) - - def __rmod__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__rmod__(other), - ) - - def __rmul__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__rmul__(other), - ) - - def __ror__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__ror__(other), - ) - - def __rpow__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__rpow__(other), - ) - - def __rsub__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__rsub__(other), - ) - - def __rtruediv__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__rtruediv__(other), - ) - - def __rxor__(self, other) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__rxor__(other), - ) - - # Unary operators ---------------------------------------------------------- + other = _unwrap(other) + return _wrap(self._series.__eq__(other)) + + def __ge__(self, other: Any) -> ExperimentalPolarsCell[bool]: + other = _unwrap(other) + return _wrap(self._series.__ge__(other)) + + def __gt__(self, other: Any) -> ExperimentalPolarsCell[bool]: + other = _unwrap(other) + return _wrap(self._series.__gt__(other)) + + def __le__(self, other: Any) -> ExperimentalPolarsCell[bool]: + other = _unwrap(other) + return _wrap(self._series.__le__(other)) + + def __lt__(self, other: Any) -> ExperimentalPolarsCell[bool]: + other = _unwrap(other) + return _wrap(self._series.__lt__(other)) + + # Numeric operators -------------------------------------------------------- def __abs__(self) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__abs__(), - ) + return _wrap(self._series.__abs__()) def __neg__(self) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__neg__(), - ) + return _wrap(self._series.__neg__()) def __pos__(self) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__pos__(), - ) + return _wrap(self._series.__pos__()) + + def __add__(self, other: Any) -> ExperimentalPolarsCell[R]: + other = _unwrap(other) + return _wrap(self._series.__add__(other)) + + def __radd__(self, other: Any) -> ExperimentalPolarsCell[R]: + other = _unwrap(other) + return _wrap(self._series.__radd__(other)) + + def __floordiv__(self, other: Any) -> ExperimentalPolarsCell[R]: + other = _unwrap(other) + return _wrap(self._series.__floordiv__(other)) + + def __rfloordiv__(self, other: Any) -> ExperimentalPolarsCell[R]: + other = _unwrap(other) + return _wrap(self._series.__rfloordiv__(other)) - def __invert__(self) -> ExperimentalPolarsCell[R]: - return ExperimentalPolarsColumn._from_polars_series( - self._series.__invert__(), - ) + def __mod__(self, other: Any) -> ExperimentalPolarsCell[R]: + other = _unwrap(other) + return _wrap(self._series.__mod__(other)) + + def __rmod__(self, other: Any) -> ExperimentalPolarsCell[R]: + other = _unwrap(other) + return _wrap(self._series.__rmod__(other)) + + def __mul__(self, other: Any) -> ExperimentalPolarsCell[R]: + other = _unwrap(other) + return _wrap(self._series.__mul__(other)) + + def __rmul__(self, other: Any) -> ExperimentalPolarsCell[R]: + other = _unwrap(other) + return _wrap(self._series.__rmul__(other)) + + def __pow__(self, other: float | ExperimentalPolarsCell[P]) -> ExperimentalPolarsCell[R]: + other = _unwrap(other) + return _wrap(self._series.__pow__(other)) + + def __rpow__(self, other: float | ExperimentalPolarsCell[P]) -> ExperimentalPolarsCell[R]: + other = _unwrap(other) + return _wrap(self._series.__rpow__(other)) + + def __sub__(self, other: Any) -> ExperimentalPolarsCell[R]: + other = _unwrap(other) + return _wrap(self._series.__sub__(other)) + + def __rsub__(self, other: Any) -> ExperimentalPolarsCell[R]: + other = _unwrap(other) + return _wrap(self._series.__rsub__(other)) + + def __truediv__(self, other: Any) -> ExperimentalPolarsCell[R]: + other = _unwrap(other) + return _wrap(self._series.__truediv__(other)) + + def __rtruediv__(self, other: Any) -> ExperimentalPolarsCell[R]: + other = _unwrap(other) + return _wrap(self._series.__rtruediv__(other)) + + # String representation ---------------------------------------------------- + + def __repr__(self) -> str: + return self._series.__repr__() + + def __str__(self) -> str: + return self._series.__str__() # Other -------------------------------------------------------------------- @@ -235,3 +199,13 @@ def __hash__(self) -> int: def __sizeof__(self) -> int: raise NotImplementedError + + +def _wrap(other: Series) -> Any: + return ExperimentalPolarsColumn._from_polars_series(other) + + +def _unwrap(other: Any) -> Any: + if isinstance(other, ExperimentalPolarsColumn): + return other._series + return other From fd476a2d04ff19bd9217d1284a7ae580cb655ba3 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 7 May 2024 00:23:21 +0200 Subject: [PATCH 4/6] feat: check operands of boolean operations --- .../containers/_experimental_polars_cell.py | 4 + .../containers/_experimental_polars_column.py | 74 +++++++++++++++---- 2 files changed, 65 insertions(+), 13 deletions(-) diff --git a/src/safeds/data/tabular/containers/_experimental_polars_cell.py b/src/safeds/data/tabular/containers/_experimental_polars_cell.py index 81c2cea7c..e99357747 100644 --- a/src/safeds/data/tabular/containers/_experimental_polars_cell.py +++ b/src/safeds/data/tabular/containers/_experimental_polars_cell.py @@ -67,6 +67,10 @@ def __le__(self, other: Any) -> ExperimentalPolarsCell[bool]: def __lt__(self, other: Any) -> ExperimentalPolarsCell[bool]: ... + @abstractmethod + def __ne__(self, other: object) -> ExperimentalPolarsCell[bool]: + ... + # Numeric operators -------------------------------------------------------- @abstractmethod diff --git a/src/safeds/data/tabular/containers/_experimental_polars_column.py b/src/safeds/data/tabular/containers/_experimental_polars_column.py index e688933f9..92ae5eaed 100644 --- a/src/safeds/data/tabular/containers/_experimental_polars_column.py +++ b/src/safeds/data/tabular/containers/_experimental_polars_column.py @@ -55,31 +55,54 @@ def __init__(self, name: str, data: Sequence[T] | None = None) -> None: # "Boolean" operators (actually bitwise) ----------------------------------- def __invert__(self) -> ExperimentalPolarsCell[bool]: - return _wrap(self._series.__invert__().cast(bool)) + import polars as pl + + if self._series.dtype != pl.Boolean: + return NotImplemented + + return _wrap(self._series.__invert__()) def __and__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - other = _unwrap(other) - return _wrap(self._series.__and__(other).cast(bool)) + other = _normalize_boolean_operation_operands(self, other) + if other is None: + return NotImplemented + + return _wrap(self._series.__and__(other)) def __rand__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - other = _unwrap(other) - return _wrap(self._series.__rand__(other).cast(bool)) + other = _normalize_boolean_operation_operands(self, other) + if other is None: + return NotImplemented + + return _wrap(self._series.__rand__(other)) def __or__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - other = _unwrap(other) - return _wrap(self._series.__or__(other).cast(bool)) + other = _normalize_boolean_operation_operands(self, other) + if other is None: + return NotImplemented + + return _wrap(self._series.__or__(other)) def __ror__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - other = _unwrap(other) - return _wrap(self._series.__ror__(other).cast(bool)) + other = _normalize_boolean_operation_operands(self, other) + if other is None: + return NotImplemented + + return _wrap(self._series.__ror__(other)) def __xor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - other = _unwrap(other) - return _wrap(self._series.__xor__(other).cast(bool)) + other = _normalize_boolean_operation_operands(self, other) + if other is None: + return NotImplemented + + return _wrap(self._series.__xor__(other)) def __rxor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - other = _unwrap(other) - return _wrap(self._series.__rxor__(other).cast(bool)) + other = _normalize_boolean_operation_operands(self, other) + if other is None: + return NotImplemented + + return _wrap(self._series.__rxor__(other)) # Collection --------------------------------------------------------------- @@ -117,6 +140,10 @@ def __lt__(self, other: Any) -> ExperimentalPolarsCell[bool]: other = _unwrap(other) return _wrap(self._series.__lt__(other)) + def __ne__(self, other: object) -> ExperimentalPolarsCell[bool]: + other = _unwrap(other) + return _wrap(self._series.__ne__(other)) + # Numeric operators -------------------------------------------------------- def __abs__(self) -> ExperimentalPolarsCell[R]: @@ -201,6 +228,27 @@ def __sizeof__(self) -> int: raise NotImplementedError +def _normalize_boolean_operation_operands( + left_operand: ExperimentalPolarsColumn, + right_operand: bool | ExperimentalPolarsCell[bool], +) -> Series | None: + """ + Normalize the operands of a boolean operation (not, and, or, xor). + + If one of the operands is invalid, None is returned. Otherwise, the normalized right operand is returned. + """ + import polars as pl + + if left_operand._series.dtype != pl.Boolean: + return None + elif isinstance(right_operand, bool): + return pl.Series("", [right_operand]) + elif not isinstance(right_operand, ExperimentalPolarsColumn) or right_operand._series.dtype != pl.Boolean: + return None + else: + return right_operand._series + + def _wrap(other: Series) -> Any: return ExperimentalPolarsColumn._from_polars_series(other) From 2a1e7f7710b087627848fca4d3c186e2dd4f1ade Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 7 May 2024 00:39:31 +0200 Subject: [PATCH 5/6] fix: mypy errors --- .../containers/_experimental_polars_cell.py | 4 +- .../containers/_experimental_polars_column.py | 44 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/safeds/data/tabular/containers/_experimental_polars_cell.py b/src/safeds/data/tabular/containers/_experimental_polars_cell.py index e99357747..4b0a949aa 100644 --- a/src/safeds/data/tabular/containers/_experimental_polars_cell.py +++ b/src/safeds/data/tabular/containers/_experimental_polars_cell.py @@ -48,7 +48,7 @@ def __rxor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPo # Comparison --------------------------------------------------------------- @abstractmethod - def __eq__(self, other: object) -> ExperimentalPolarsCell[bool]: + def __eq__(self, other: object) -> ExperimentalPolarsCell[bool]: # type: ignore[override] ... @abstractmethod @@ -68,7 +68,7 @@ def __lt__(self, other: Any) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __ne__(self, other: object) -> ExperimentalPolarsCell[bool]: + def __ne__(self, other: object) -> ExperimentalPolarsCell[bool]: # type: ignore[override] ... # Numeric operators -------------------------------------------------------- diff --git a/src/safeds/data/tabular/containers/_experimental_polars_column.py b/src/safeds/data/tabular/containers/_experimental_polars_column.py index 92ae5eaed..163464349 100644 --- a/src/safeds/data/tabular/containers/_experimental_polars_column.py +++ b/src/safeds/data/tabular/containers/_experimental_polars_column.py @@ -63,46 +63,46 @@ def __invert__(self) -> ExperimentalPolarsCell[bool]: return _wrap(self._series.__invert__()) def __and__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - other = _normalize_boolean_operation_operands(self, other) - if other is None: + right_operand = _normalize_boolean_operation_operands(self, other) + if right_operand is None: return NotImplemented - return _wrap(self._series.__and__(other)) + return _wrap(self._series.__and__(right_operand)) def __rand__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - other = _normalize_boolean_operation_operands(self, other) - if other is None: + right_operand = _normalize_boolean_operation_operands(self, other) + if right_operand is None: return NotImplemented - return _wrap(self._series.__rand__(other)) + return _wrap(self._series.__rand__(right_operand)) def __or__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - other = _normalize_boolean_operation_operands(self, other) - if other is None: + right_operand = _normalize_boolean_operation_operands(self, other) + if right_operand is None: return NotImplemented - return _wrap(self._series.__or__(other)) + return _wrap(self._series.__or__(right_operand)) def __ror__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - other = _normalize_boolean_operation_operands(self, other) - if other is None: + right_operand = _normalize_boolean_operation_operands(self, other) + if right_operand is None: return NotImplemented - return _wrap(self._series.__ror__(other)) + return _wrap(self._series.__ror__(right_operand)) def __xor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - other = _normalize_boolean_operation_operands(self, other) - if other is None: + right_operand = _normalize_boolean_operation_operands(self, other) + if right_operand is None: return NotImplemented - return _wrap(self._series.__xor__(other)) + return _wrap(self._series.__xor__(right_operand)) def __rxor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - other = _normalize_boolean_operation_operands(self, other) - if other is None: + right_operand = _normalize_boolean_operation_operands(self, other) + if right_operand is None: return NotImplemented - return _wrap(self._series.__rxor__(other)) + return _wrap(self._series.__rxor__(right_operand)) # Collection --------------------------------------------------------------- @@ -110,9 +110,9 @@ def __rxor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPo def __getitem__(self, index: int) -> T: ... @overload - def __getitem__(self, index: slice) -> T: ... + def __getitem__(self, index: slice) -> ExperimentalPolarsColumn[T]: ... - def __getitem__(self, index: int | slice) -> T: + def __getitem__(self, index: int | slice) -> T | ExperimentalPolarsColumn[T]: return self._series.__getitem__(index) def __len__(self) -> int: @@ -120,7 +120,7 @@ def __len__(self) -> int: # Comparison --------------------------------------------------------------- - def __eq__(self, other: object) -> ExperimentalPolarsCell[bool]: + def __eq__(self, other: object) -> ExperimentalPolarsCell[bool]: # type: ignore[override] other = _unwrap(other) return _wrap(self._series.__eq__(other)) @@ -140,7 +140,7 @@ def __lt__(self, other: Any) -> ExperimentalPolarsCell[bool]: other = _unwrap(other) return _wrap(self._series.__lt__(other)) - def __ne__(self, other: object) -> ExperimentalPolarsCell[bool]: + def __ne__(self, other: object) -> ExperimentalPolarsCell[bool]: # type: ignore[override] other = _unwrap(other) return _wrap(self._series.__ne__(other)) From afddd02306ecfaebc92de077c7d5a8066d0d2456 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Mon, 6 May 2024 22:41:21 +0000 Subject: [PATCH 6/6] style: apply automated linter fixes --- .../containers/_experimental_polars_cell.py | 90 +++++++------------ 1 file changed, 30 insertions(+), 60 deletions(-) diff --git a/src/safeds/data/tabular/containers/_experimental_polars_cell.py b/src/safeds/data/tabular/containers/_experimental_polars_cell.py index 4b0a949aa..48a5368a7 100644 --- a/src/safeds/data/tabular/containers/_experimental_polars_cell.py +++ b/src/safeds/data/tabular/containers/_experimental_polars_cell.py @@ -18,32 +18,25 @@ class ExperimentalPolarsCell(ABC, Generic[T]): # "Boolean" operators (actually bitwise) ----------------------------------- @abstractmethod - def __invert__(self) -> ExperimentalPolarsCell[bool]: - ... + def __invert__(self) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __and__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - ... + def __and__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __rand__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - ... + def __rand__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __or__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - ... + def __or__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __ror__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - ... + def __ror__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __xor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - ... + def __xor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __rxor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: - ... + def __rxor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ... # Comparison --------------------------------------------------------------- @@ -52,20 +45,16 @@ def __eq__(self, other: object) -> ExperimentalPolarsCell[bool]: # type: ignore ... @abstractmethod - def __ge__(self, other: Any) -> ExperimentalPolarsCell[bool]: - ... + def __ge__(self, other: Any) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __gt__(self, other: Any) -> ExperimentalPolarsCell[bool]: - ... + def __gt__(self, other: Any) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __le__(self, other: Any) -> ExperimentalPolarsCell[bool]: - ... + def __le__(self, other: Any) -> ExperimentalPolarsCell[bool]: ... @abstractmethod - def __lt__(self, other: Any) -> ExperimentalPolarsCell[bool]: - ... + def __lt__(self, other: Any) -> ExperimentalPolarsCell[bool]: ... @abstractmethod def __ne__(self, other: object) -> ExperimentalPolarsCell[bool]: # type: ignore[override] @@ -74,79 +63,60 @@ def __ne__(self, other: object) -> ExperimentalPolarsCell[bool]: # type: ignore # Numeric operators -------------------------------------------------------- @abstractmethod - def __abs__(self) -> ExperimentalPolarsCell[R]: - ... + def __abs__(self) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __neg__(self) -> ExperimentalPolarsCell[R]: - ... + def __neg__(self) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __pos__(self) -> ExperimentalPolarsCell[R]: - ... + def __pos__(self) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __add__(self, other: Any) -> ExperimentalPolarsCell[R]: - ... + def __add__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __radd__(self, other: Any) -> ExperimentalPolarsCell[R]: - ... + def __radd__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __floordiv__(self, other: Any) -> ExperimentalPolarsCell[R]: - ... + def __floordiv__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rfloordiv__(self, other: Any) -> ExperimentalPolarsCell[R]: - ... + def __rfloordiv__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __mod__(self, other: Any) -> ExperimentalPolarsCell[R]: - ... + def __mod__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rmod__(self, other: Any) -> ExperimentalPolarsCell[R]: - ... + def __rmod__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __mul__(self, other: Any) -> ExperimentalPolarsCell[R]: - ... + def __mul__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rmul__(self, other: Any) -> ExperimentalPolarsCell[R]: - ... + def __rmul__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __pow__(self, other: float | ExperimentalPolarsCell[P]) -> ExperimentalPolarsCell[R]: - ... + def __pow__(self, other: float | ExperimentalPolarsCell[P]) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rpow__(self, other: float | ExperimentalPolarsCell[P]) -> ExperimentalPolarsCell[R]: - ... + def __rpow__(self, other: float | ExperimentalPolarsCell[P]) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __sub__(self, other: Any) -> ExperimentalPolarsCell[R]: - ... + def __sub__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rsub__(self, other: Any) -> ExperimentalPolarsCell[R]: - ... + def __rsub__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __truediv__(self, other: Any) -> ExperimentalPolarsCell[R]: - ... + def __truediv__(self, other: Any) -> ExperimentalPolarsCell[R]: ... @abstractmethod - def __rtruediv__(self, other: Any) -> ExperimentalPolarsCell[R]: - ... + def __rtruediv__(self, other: Any) -> ExperimentalPolarsCell[R]: ... # Other -------------------------------------------------------------------- @abstractmethod - def __hash__(self) -> int: - ... + def __hash__(self) -> int: ... @abstractmethod - def __sizeof__(self) -> int: - ... + def __sizeof__(self) -> int: ...