diff --git a/src/safeds/data/tabular/containers/_column.py b/src/safeds/data/tabular/containers/_column.py index 6c7b790fa..85edd4ba5 100644 --- a/src/safeds/data/tabular/containers/_column.py +++ b/src/safeds/data/tabular/containers/_column.py @@ -112,8 +112,8 @@ def __init__( # Implementation self._name: str = name - self._lazy_frame: pl.LazyFrame = pl.LazyFrame(data, schema={name: dtype}, strict=False) - self.__series_cache: pl.Series | None = None + self.__series_cache: pl.Series | None = pl.Series(name, data, dtype=dtype, strict=False) + self._lazy_frame: pl.LazyFrame = self.__series_cache.to_frame().lazy() def __contains__(self, value: object) -> bool: import polars as pl diff --git a/src/safeds/data/tabular/query/_lazy_string_operations.py b/src/safeds/data/tabular/query/_lazy_string_operations.py index cb9a2790a..c5750d48c 100644 --- a/src/safeds/data/tabular/query/_lazy_string_operations.py +++ b/src/safeds/data/tabular/query/_lazy_string_operations.py @@ -3,7 +3,7 @@ from typing import TYPE_CHECKING from safeds._utils import _structural_hash -from safeds._validation import _convert_and_check_datetime_format +from safeds._validation import _convert_and_check_datetime_format, _check_bounds, _ClosedBound from safeds.data.tabular.containers._lazy_cell import _LazyCell from ._string_operations import StringOperations @@ -75,9 +75,12 @@ def substring( start: _ConvertibleToIntCell = 0, length: _ConvertibleToIntCell = None, ) -> Cell[str | None]: + if isinstance(length, int): + _check_bounds("length", length, lower_bound=_ClosedBound(0)) + return _LazyCell(self._expression.str.slice(start, length)) - def to_date(self, *, format: str | None = None) -> Cell[datetime.date | None]: + def to_date(self, *, format: str | None = "iso") -> Cell[datetime.date | None]: if format == "iso": format = "%F" # noqa: A001 elif format is not None: @@ -85,7 +88,7 @@ def to_date(self, *, format: str | None = None) -> Cell[datetime.date | None]: return _LazyCell(self._expression.str.to_date(format=format, strict=False)) - def to_datetime(self, *, format: str | None = None) -> Cell[datetime.datetime | None]: + def to_datetime(self, *, format: str | None = "iso") -> Cell[datetime.datetime | None]: if format == "iso": format = "%+" # noqa: A001 elif format is not None: @@ -99,7 +102,7 @@ def to_int(self, *, base: _ConvertibleToIntCell = 10) -> Cell[int | None]: def to_lowercase(self) -> Cell[str | None]: return _LazyCell(self._expression.str.to_lowercase()) - def to_time(self, *, format: str | None = None) -> Cell[datetime.time | None]: + def to_time(self, *, format: str | None = "iso") -> Cell[datetime.time | None]: if format == "iso": format = "%T" # noqa: A001 elif format is not None: diff --git a/src/safeds/data/tabular/query/_string_operations.py b/src/safeds/data/tabular/query/_string_operations.py index 0284d6029..6b99afe59 100644 --- a/src/safeds/data/tabular/query/_string_operations.py +++ b/src/safeds/data/tabular/query/_string_operations.py @@ -303,7 +303,7 @@ def substring( # TODO: add format parameter + document @abstractmethod - def to_date(self, *, format: str | None = None) -> Cell[datetime.date | None]: + def to_date(self, *, format: str | None = "iso") -> Cell[datetime.date | None]: """ Convert the string value in the cell to a date. @@ -331,7 +331,7 @@ def to_date(self, *, format: str | None = None) -> Cell[datetime.date | None]: # TODO: add format parameter + document @abstractmethod - def to_datetime(self, *, format: str | None = None) -> Cell[datetime.datetime | None]: + def to_datetime(self, *, format: str | None = "iso") -> Cell[datetime.datetime | None]: """ Convert the string value in the cell to a datetime.