Skip to content

Commit

Permalink
feat: Basic implementation of cell with polars (#734)
Browse files Browse the repository at this point in the history
Closes partially #712

### Summary of Changes

Add a basic implementation of a cell backed by a **Column**. This allows
vectorized computations. For now, only some operators are overwritten.

---------

Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
  • Loading branch information
lars-reimann and megalinter-bot committed May 6, 2024
1 parent ff627f6 commit 004630b
Show file tree
Hide file tree
Showing 5 changed files with 380 additions and 22 deletions.
10 changes: 10 additions & 0 deletions src/safeds/data/tabular/containers/_experimental_lazy_column.py
Original file line number Diff line number Diff line change
@@ -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
118 changes: 115 additions & 3 deletions src/safeds/data/tabular/containers/_experimental_polars_cell.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,122 @@
from __future__ import annotations

from abc import ABC
from typing import Generic, TypeVar
from abc import ABC, abstractmethod
from typing import Any, Generic, TypeVar

T = TypeVar("T")
P = TypeVar("P")
R = TypeVar("R")


class ExperimentalPolarsCell(ABC, Generic[T]):
pass
"""A cell is a single value in a table."""

# ------------------------------------------------------------------------------------------------------------------
# Dunder methods
# ------------------------------------------------------------------------------------------------------------------

# "Boolean" operators (actually bitwise) -----------------------------------

@abstractmethod
def __invert__(self) -> ExperimentalPolarsCell[bool]: ...

@abstractmethod
def __and__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ...

@abstractmethod
def __rand__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ...

@abstractmethod
def __or__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ...

@abstractmethod
def __ror__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ...

@abstractmethod
def __xor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ...

@abstractmethod
def __rxor__(self, other: bool | ExperimentalPolarsCell[bool]) -> ExperimentalPolarsCell[bool]: ...

# Comparison ---------------------------------------------------------------

@abstractmethod
def __eq__(self, other: object) -> ExperimentalPolarsCell[bool]: # type: ignore[override]
...

@abstractmethod
def __ge__(self, other: Any) -> ExperimentalPolarsCell[bool]: ...

@abstractmethod
def __gt__(self, other: Any) -> ExperimentalPolarsCell[bool]: ...

@abstractmethod
def __le__(self, other: Any) -> ExperimentalPolarsCell[bool]: ...

@abstractmethod
def __lt__(self, other: Any) -> ExperimentalPolarsCell[bool]: ...

@abstractmethod
def __ne__(self, other: object) -> ExperimentalPolarsCell[bool]: # type: ignore[override]
...

# Numeric operators --------------------------------------------------------

@abstractmethod
def __abs__(self) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __neg__(self) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __pos__(self) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __add__(self, other: Any) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __radd__(self, other: Any) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __floordiv__(self, other: Any) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __rfloordiv__(self, other: Any) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __mod__(self, other: Any) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __rmod__(self, other: Any) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __mul__(self, other: Any) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __rmul__(self, other: Any) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __pow__(self, other: float | ExperimentalPolarsCell[P]) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __rpow__(self, other: float | ExperimentalPolarsCell[P]) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __sub__(self, other: Any) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __rsub__(self, other: Any) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __truediv__(self, other: Any) -> ExperimentalPolarsCell[R]: ...

@abstractmethod
def __rtruediv__(self, other: Any) -> ExperimentalPolarsCell[R]: ...

# Other --------------------------------------------------------------------

@abstractmethod
def __hash__(self) -> int: ...

@abstractmethod
def __sizeof__(self) -> int: ...

0 comments on commit 004630b

Please sign in to comment.