Skip to content
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
467 changes: 329 additions & 138 deletions poetry.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/safeds/data/tabular/containers/_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ def datetime(
year: _ConvertibleToIntCell,
month: _ConvertibleToIntCell,
day: _ConvertibleToIntCell,
hour: _ConvertibleToIntCell,
minute: _ConvertibleToIntCell,
second: _ConvertibleToIntCell,
*,
hour: _ConvertibleToIntCell = 0,
minute: _ConvertibleToIntCell = 0,
second: _ConvertibleToIntCell = 0,
microsecond: _ConvertibleToIntCell = 0,
time_zone: str | None = None,
) -> Cell[python_datetime.datetime | None]:
Expand Down Expand Up @@ -193,7 +193,7 @@ def datetime(
--------
>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", [1, 2, None])
>>> column.transform(lambda _: Cell.datetime(2025, 1, 15, hour=12))
>>> column.transform(lambda _: Cell.datetime(2025, 1, 15, 12, 0 ,0))
+---------------------+
| a |
| --- |
Expand All @@ -204,7 +204,7 @@ def datetime(
| 2025-01-15 12:00:00 |
+---------------------+

>>> column.transform(lambda cell: Cell.datetime(2025, 1, 15, hour=cell))
>>> column.transform(lambda cell: Cell.datetime(2025, 1, 15, cell, 0, 0))
+---------------------+
| a |
| --- |
Expand Down
2 changes: 1 addition & 1 deletion src/safeds/data/tabular/query/_datetime_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def week(self) -> Cell[int | None]:
| null |
+------+

>>> column2 = Column("a", [date(1999, 12, 31), date(2000, 1, 2), datetime(2001, 12, 31), None])
>>> column2 = Column("a", [date(1999, 12, 31), date(2000, 1, 2), date(2001, 12, 31), None])
>>> column2.transform(lambda cell: cell.dt.week())
+------+
| a |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# serializer version: 1
# name: TestContract.test_should_return_same_hash_in_different_processes[column]
1166043995912835534
2158421768275916388
# ---
# name: TestContract.test_should_return_same_hash_in_different_processes[constant]
161664381415222824
795242721712471450
# ---
# name: TestContract.test_should_return_same_hash_in_different_processes[date, column]
1658093798669947354
3029334420570699438
# ---
# name: TestContract.test_should_return_same_hash_in_different_processes[date, int]
2015176867097674126
2441473117647356403
# ---
42 changes: 30 additions & 12 deletions tests/safeds/data/tabular/containers/_lazy_cell/test_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import pytest

from safeds._typing import _ConvertibleToIntCell
from safeds.data.tabular.containers import Cell
from safeds.data.tabular.containers import Cell, Column
from safeds.exceptions import LazyComputationError
from tests.helpers import assert_cell_operation_works


Expand All @@ -12,27 +13,17 @@
[
(1, 2, 3, date(1, 2, 3)),
(Cell.constant(1), Cell.constant(2), Cell.constant(3), date(1, 2, 3)),
# invalid year
# with None components
(None, 2, 3, None),
# invalid month
(1, None, 3, None),
(1, 0, 3, None),
(1, 13, 3, None),
# invalid day
(1, 2, None, None),
(1, 2, 0, None),
(1, 2, 32, None),
],
ids=[
"int components",
"cell components",
"year is None",
"month is None",
"month is too low",
"month is too high",
"day is None",
"day is too low",
"day is too high",
],
)
def test_should_return_date(
Expand All @@ -42,3 +33,30 @@ def test_should_return_date(
expected: date,
) -> None:
assert_cell_operation_works(None, lambda _: Cell.date(year, month, day), expected)


@pytest.mark.parametrize(
("year", "month", "day"),
[
# invalid month
(1, 0, 3),
(1, 13, 3),
# invalid day
(1, 2, 0),
(1, 2, 32),
],
ids=[
"month is too low",
"month is too high",
"day is too low",
"day is too high",
],
)
def test_should_raise_for_invalid_components(
year: _ConvertibleToIntCell,
month: _ConvertibleToIntCell,
day: _ConvertibleToIntCell,
) -> None:
column = Column("col1", [None])
with pytest.raises(LazyComputationError):
column.transform(lambda _: Cell.date(year, month, day)).get_value(0)
99 changes: 66 additions & 33 deletions tests/safeds/data/tabular/containers/_lazy_cell/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from safeds._typing import _ConvertibleToIntCell
from safeds.data.tabular.containers import Cell, Column
from safeds.exceptions import LazyComputationError
from tests.helpers import assert_cell_operation_works


Expand Down Expand Up @@ -32,32 +33,14 @@
None,
datetime(1, 2, 3, 4, 5, 6, 7), # noqa: DTZ001
),
# invalid year
# with None components
(None, 2, 3, 4, 5, 6, 7, None, None),
# invalid month
(1, None, 3, 4, 5, 6, 7, None, None),
(1, 0, 3, 4, 5, 6, 7, None, None),
(1, 13, 3, 4, 5, 6, 7, None, None),
# invalid day
(1, 2, None, 4, 5, 6, 7, None, None),
(1, 2, 0, 4, 5, 6, 7, None, None),
(1, 2, 32, 4, 5, 6, 7, None, None),
# invalid hour
(1, 2, 3, None, 5, 6, 7, None, None),
(1, 2, 3, -1, 5, 6, 7, None, None),
(1, 2, 3, 24, 5, 6, 7, None, None),
# invalid minute
(1, 2, 3, 4, None, 6, 7, None, None),
(1, 2, 3, 4, -1, 6, 7, None, None),
(1, 2, 3, 4, 60, 6, 7, None, None),
# invalid second
(1, 2, 3, 4, 5, None, 7, None, None),
(1, 2, 3, 4, 5, -1, 7, None, None),
(1, 2, 3, 4, 5, 60, 7, None, None),
# invalid microsecond
(1, 2, 3, 4, 5, 6, None, None, None),
(1, 2, 3, 4, 5, 6, -1, None, None),
(1, 2, 3, 4, 5, 6, 1_000_000, None, None),
# with time zone
(1, 2, 3, 4, 5, 6, 7, "UTC", datetime(1, 2, 3, 4, 5, 6, 7, tzinfo=UTC)),
],
Expand All @@ -66,23 +49,11 @@
"cell components",
"year is None",
"month is None",
"month is too low",
"month is too high",
"day is None",
"day is too low",
"day is too high",
"hour is None",
"hour is too low",
"hour is too high",
"minute is None",
"minute is too low",
"minute is too high",
"second is None",
"second is too low",
"second is too high",
"microsecond is None",
"microsecond is too low",
"microsecond is too high",
"with time zone",
],
)
Expand Down Expand Up @@ -113,7 +84,69 @@ def test_should_return_datetime(
)


@pytest.mark.parametrize(
("year", "month", "day", "hour", "minute", "second", "microsecond"),
[
# invalid month
(1, 0, 3, 4, 5, 6, 7),
(1, 13, 3, 4, 5, 6, 7),
# invalid day
(1, 2, 0, 4, 5, 6, 7),
(1, 2, 32, 4, 5, 6, 7),
# invalid hour
(1, 2, 3, -1, 5, 6, 7),
(1, 2, 3, 24, 5, 6, 7),
# invalid minute
(1, 2, 3, 4, -1, 6, 7),
(1, 2, 3, 4, 60, 6, 7),
# invalid second
(1, 2, 3, 4, 5, -1, 7),
(1, 2, 3, 4, 5, 60, 7),
# invalid microsecond
(1, 2, 3, 4, 5, 6, -1),
pytest.param(
1,
2,
3,
4,
5,
6,
1_000_000,
marks=pytest.mark.xfail(reason="https://github.com/pola-rs/polars/issues/21664"),
),
],
ids=[
"month is too low",
"month is too high",
"day is too low",
"day is too high",
"hour is too low",
"hour is too high",
"minute is too low",
"minute is too high",
"second is too low",
"second is too high",
"microsecond is too low",
"microsecond is too high",
],
)
def test_should_raise_for_invalid_components(
year: _ConvertibleToIntCell,
month: _ConvertibleToIntCell,
day: _ConvertibleToIntCell,
hour: _ConvertibleToIntCell,
minute: _ConvertibleToIntCell,
second: _ConvertibleToIntCell,
microsecond: _ConvertibleToIntCell,
) -> None:
column = Column("col1", [None])
with pytest.raises(LazyComputationError):
column.transform(
lambda _: Cell.datetime(year, month, day, hour, minute, second, microsecond=microsecond),
).get_value(0)


def test_should_raise_if_time_zone_is_invalid() -> None:
column = Column("a", [None])
column = Column("col1", [None])
with pytest.raises(ValueError, match="Invalid time zone"):
column.transform(lambda _: Cell.datetime(1, 2, 3, time_zone="invalid"))
column.transform(lambda _: Cell.datetime(1, 2, 3, 0, 0, 0, time_zone="invalid"))
66 changes: 45 additions & 21 deletions tests/safeds/data/tabular/containers/_lazy_cell/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import pytest

from safeds._typing import _ConvertibleToIntCell
from safeds.data.tabular.containers import Cell
from safeds.data.tabular.containers import Cell, Column
from safeds.exceptions import LazyComputationError
from tests.helpers import assert_cell_operation_works


Expand All @@ -12,38 +13,19 @@
[
(1, 2, 3, 4, time(1, 2, 3, 4)),
(Cell.constant(1), Cell.constant(2), Cell.constant(3), Cell.constant(4), time(1, 2, 3, 4)),
# invalid hour
# with None components
(None, 2, 3, 4, None),
(-1, 2, 3, 4, None),
(24, 2, 3, 4, None),
# invalid minute
(1, None, 3, 4, None),
(1, -1, 3, 4, None),
(1, 60, 3, 4, None),
# invalid second
(1, 2, None, 4, None),
(1, 2, -1, 4, None),
(1, 2, 60, 4, None),
# invalid microsecond
(1, 2, 3, None, None),
(1, 2, 3, -1, None),
(1, 2, 3, 1_000_000, None),
],
ids=[
"int components",
"cell components",
"hour is None",
"hour is too low",
"hour is too high",
"minute is None",
"minute is too low",
"minute is too high",
"second is None",
"second is too low",
"second is too high",
"microsecond is None",
"microsecond is too low",
"microsecond is too high",
],
)
def test_should_return_time(
Expand All @@ -58,3 +40,45 @@ def test_should_return_time(
lambda _: Cell.time(hour, minute, second, microsecond=microsecond),
expected,
)


@pytest.mark.parametrize(
("hour", "minute", "second", "microsecond"),
[
# invalid hour
(-1, 2, 3, 4),
(24, 2, 3, 4),
# invalid minute
(1, -1, 3, 4),
(1, 60, 3, 4),
# invalid second
(1, 2, -1, 4),
(1, 2, 60, 4),
# invalid microsecond
(1, 2, 3, -1),
pytest.param(
1, 2, 3, 1_000_000, marks=pytest.mark.xfail(reason="https://github.com/pola-rs/polars/issues/21664"),
),
],
ids=[
"hour is too low",
"hour is too high",
"minute is too low",
"minute is too high",
"second is too low",
"second is too high",
"microsecond is too low",
"microsecond is too high",
],
)
def test_should_raise_for_invalid_components(
hour: _ConvertibleToIntCell,
minute: _ConvertibleToIntCell,
second: _ConvertibleToIntCell,
microsecond: _ConvertibleToIntCell,
) -> None:
column = Column("col1", [None])
with pytest.raises(LazyComputationError):
column.transform(
lambda _: Cell.time(hour, minute, second, microsecond=microsecond),
).get_value(0)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# serializer version: 1
# name: TestContract.test_should_return_same_hash_in_different_processes[column]
1166043995912835534
2158421768275916388
# ---
# name: TestContract.test_should_return_same_hash_in_different_processes[time]
766453026781410313
7215503084941727838
# ---
Loading
Loading