-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Basic implementation of cell with polars (#734)
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 <[email protected]>
- Loading branch information
1 parent
ff627f6
commit 004630b
Showing
5 changed files
with
380 additions
and
22 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/safeds/data/tabular/containers/_experimental_lazy_column.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
118
src/safeds/data/tabular/containers/_experimental_polars_cell.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: ... |
Oops, something went wrong.