Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9b28d5a
docs: normalize examples
lars-reimann Jan 14, 2025
ad84a51
feat: create cell from date/time/datetime/duration
lars-reimann Jan 14, 2025
e3abb1a
feat: cast cells
lars-reimann Jan 14, 2025
a79c0ea
feat: catch errors when collecting polars lazy frames
lars-reimann Jan 14, 2025
5fa05aa
chore: improve type hints
lars-reimann Jan 14, 2025
9cb8a19
feat: by default, `None` propagates now in `eq` and `neq`
lars-reimann Jan 14, 2025
9f57ce0
feat: add parameter to control whether missing values should be propa…
lars-reimann Jan 14, 2025
bd4b009
chore: check boolean operations
lars-reimann Jan 15, 2025
6973d39
chore: fix type hints for comparison operations
lars-reimann Jan 15, 2025
a95b005
chore: check tests for numeric operations
lars-reimann Jan 15, 2025
9b55778
chore: check numeric operations
lars-reimann Jan 15, 2025
dd24d50
chore: check `_equals`
lars-reimann Jan 15, 2025
ddfd7c5
chore: check `__hash__`
lars-reimann Jan 15, 2025
2029989
chore: check `__str__` and `__repr__`
lars-reimann Jan 15, 2025
f2e7656
chore: check `first_not_none`
lars-reimann Jan 15, 2025
737a1b3
chore: check `cast`
lars-reimann Jan 15, 2025
f5a4e9e
chore: check `constant`
lars-reimann Jan 15, 2025
d302dfe
chore: check `date` and `time`
lars-reimann Jan 15, 2025
2420769
chore: check `datetime`
lars-reimann Jan 15, 2025
1a0ae77
chore: check `duration`
lars-reimann Jan 15, 2025
1103dc2
fix: wrong import
lars-reimann Jan 15, 2025
e4b84d7
fix: mypy errors
lars-reimann Jan 15, 2025
a70c635
style: apply automated linter fixes
megalinter-bot Jan 15, 2025
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
27 changes: 27 additions & 0 deletions src/safeds/_typing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import annotations

import datetime
from decimal import Decimal
from typing import TypeAlias

from safeds.data.tabular.containers import Cell

_NumericLiteral: TypeAlias = int | float | Decimal
_TemporalLiteral: TypeAlias = datetime.date | datetime.time | datetime.datetime | datetime.timedelta
_PythonLiteral: TypeAlias = _NumericLiteral | bool | str | bytes | _TemporalLiteral
_ConvertibleToCell: TypeAlias = _PythonLiteral | Cell | None
_BooleanCell: TypeAlias = Cell[bool | None]
# We cannot restrict `Cell`, because `Row.get_cell` returns a `Cell[Any]`.
_ConvertibleToBooleanCell: TypeAlias = bool | Cell | None
_ConvertibleToIntCell: TypeAlias = int | Cell | None


__all__ = [
"_BooleanCell",
"_ConvertibleToBooleanCell",
"_ConvertibleToCell",
"_ConvertibleToIntCell",
"_NumericLiteral",
"_PythonLiteral",
"_TemporalLiteral",
]
5 changes: 5 additions & 0 deletions src/safeds/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
if TYPE_CHECKING:
from ._collections import _compute_duplicates
from ._hashing import _structural_hash
from ._lazy import _safe_collect_lazy_frame, _safe_collect_lazy_frame_schema
from ._plotting import _figure_to_image
from ._random import _get_random_seed

Expand All @@ -15,6 +16,8 @@
{
"_compute_duplicates": "._collections:_compute_duplicates",
"_structural_hash": "._hashing:_structural_hash",
"_safe_collect_lazy_frame": "._lazy:_safe_collect_lazy_frame",
"_safe_collect_lazy_frame_schema": "._lazy:_safe_collect_lazy_frame_schema",
"_figure_to_image": "._plotting:_figure_to_image",
"_get_random_seed": "._random:_get_random_seed",
},
Expand All @@ -24,5 +27,7 @@
"_compute_duplicates",
"_figure_to_image",
"_get_random_seed",
"_safe_collect_lazy_frame",
"_safe_collect_lazy_frame_schema",
"_structural_hash",
]
62 changes: 62 additions & 0 deletions src/safeds/_utils/_lazy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from safeds.exceptions import LazyComputationError

if TYPE_CHECKING:
import polars as pl


def _safe_collect_lazy_frame(frame: pl.LazyFrame) -> pl.DataFrame:
"""
Collect a LazyFrame into a DataFrame and raise a custom error if an error occurs.

Parameters
----------
frame:
The LazyFrame to collect.

Returns
-------
frame:
The collected DataFrame.

Raises
------
LazyComputationError
If an error occurs during the computation.
"""
from polars.exceptions import PolarsError

try:
return frame.collect()
except PolarsError as e:
raise LazyComputationError(str(e)) from None


def _safe_collect_lazy_frame_schema(frame: pl.LazyFrame) -> pl.Schema:
"""
Collect the schema of a LazyFrame.

Parameters
----------
frame:
The LazyFrame to collect the schema of.

Returns
-------
schema:
The collected schema.

Raises
------
LazyComputationError
If an error occurs during the computation.
"""
from polars.exceptions import PolarsError

try:
return frame.collect_schema()
except PolarsError as e:
raise LazyComputationError(str(e)) from None
Loading