Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Basic implementation of cell with polars #734

Merged
merged 6 commits into from
May 6, 2024
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
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: ...
Loading