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: add temporal operations #832

Merged
merged 107 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 105 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
60fdde4
chaged on request
Gerhardsa0 May 8, 2024
ea01e75
chaged on request
Gerhardsa0 May 8, 2024
ec43790
chaged on request
Gerhardsa0 May 8, 2024
94ee24d
style: apply automated linter fixes
megalinter-bot May 8, 2024
cb36228
added from_str_to_temporal
Gerhardsa0 May 15, 2024
dc99f1a
picture
Gerhardsa0 May 15, 2024
a00eefa
Merge branch '740-feat-add-continues-prediction-to-outputconvertion' …
Gerhardsa0 May 15, 2024
5195ad2
merged continues pr
Gerhardsa0 May 15, 2024
0a817f4
linter change
Gerhardsa0 May 15, 2024
cce7b0e
style: apply automated linter fixes
megalinter-bot May 15, 2024
68bc442
Merge branch 'main' into 765-feat-add-temporal-operations
lars-reimann May 15, 2024
0529d38
tutorial added
Gerhardsa0 May 15, 2024
f5059e7
Merge remote-tracking branch 'origin/765-feat-add-temporal-operations…
Gerhardsa0 May 15, 2024
9ccb738
Merge branch 'main' of https://github.com/Safe-DS/Library into 765-fe…
Gerhardsa0 May 15, 2024
af3244e
added inverse for prediction
Gerhardsa0 May 16, 2024
f023b1b
test
Gerhardsa0 May 16, 2024
6e8c006
saved some changes for now
Gerhardsa0 May 16, 2024
4fc06da
added structure for temporal operations
Gerhardsa0 May 17, 2024
959b981
Merge branch 'main' of https://github.com/Safe-DS/Library into 765-fe…
Gerhardsa0 May 17, 2024
81dd2e6
added lists for visualization in lineplot
Gerhardsa0 May 20, 2024
ac2bc29
Merge branch 'main' of https://github.com/Safe-DS/Library into 765-fe…
Gerhardsa0 May 20, 2024
362426c
saved for tdy
Gerhardsa0 May 20, 2024
6409526
Merge branch 'main' of https://github.com/Safe-DS/Library into 765-fe…
Gerhardsa0 May 21, 2024
991a0e7
finished merge and added visualization
Gerhardsa0 May 21, 2024
1d2be7b
added temporal operations
Gerhardsa0 May 21, 2024
87b88c2
removed prediction name from convertionm
Gerhardsa0 May 21, 2024
1f7f6d3
moved continues to time series dataset
Gerhardsa0 May 21, 2024
045f6c9
removed learning error
Gerhardsa0 May 21, 2024
bdf976a
snapshots
Gerhardsa0 May 21, 2024
db0438c
linter changes
Gerhardsa0 May 22, 2024
b41c2ba
style: apply automated linter fixes
megalinter-bot May 22, 2024
27dca0f
style: apply automated linter fixes
megalinter-bot May 22, 2024
d24fc93
linter changes
Gerhardsa0 May 22, 2024
64770da
Merge remote-tracking branch 'origin/765-feat-add-temporal-operations…
Gerhardsa0 May 22, 2024
bdf3d72
style: apply automated linter fixes
megalinter-bot May 22, 2024
46b0fa2
fixed shape for dataloading
Gerhardsa0 May 22, 2024
4d98956
Merge remote-tracking branch 'origin/765-feat-add-temporal-operations…
Gerhardsa0 May 22, 2024
92cca07
linter changes
Gerhardsa0 May 22, 2024
3685248
linter changes
Gerhardsa0 May 22, 2024
c3ddf6c
linter changes
Gerhardsa0 May 22, 2024
5e45869
linter changes
Gerhardsa0 May 22, 2024
78ca195
adjusted dimensions
Gerhardsa0 May 22, 2024
da286d2
style: apply automated linter fixes
megalinter-bot May 22, 2024
14c1241
added temporal cells
Gerhardsa0 May 22, 2024
f97ca31
Merge remote-tracking branch 'origin/765-feat-add-temporal-operations…
Gerhardsa0 May 22, 2024
1bfebc4
added temporal cells
Gerhardsa0 May 23, 2024
7bf9926
style: apply automated linter fixes
megalinter-bot May 23, 2024
0d40ad6
adjusted test
Gerhardsa0 May 23, 2024
e1ca06e
Merge remote-tracking branch 'origin/765-feat-add-temporal-operations…
Gerhardsa0 May 23, 2024
3671ca7
adjusted test
Gerhardsa0 May 23, 2024
10cb57b
adjusted test
Gerhardsa0 May 23, 2024
56a54ab
style: apply automated linter fixes
megalinter-bot May 23, 2024
9d2367c
adjusted test
Gerhardsa0 May 23, 2024
73bedc3
Merge remote-tracking branch 'origin/765-feat-add-temporal-operations…
Gerhardsa0 May 23, 2024
dbe8907
adjusted test
Gerhardsa0 May 23, 2024
7d9bdb0
code coverage
Gerhardsa0 May 23, 2024
d210d70
linter fix
Gerhardsa0 May 23, 2024
7452aef
style: apply automated linter fixes
megalinter-bot May 23, 2024
658d12e
added code cov
Gerhardsa0 May 23, 2024
666e11f
Merge remote-tracking branch 'origin/765-feat-add-temporal-operations…
Gerhardsa0 May 23, 2024
267371a
style: apply automated linter fixes
megalinter-bot May 23, 2024
792c484
added formatstring
Gerhardsa0 May 23, 2024
8af6014
Merge remote-tracking branch 'origin/765-feat-add-temporal-operations…
Gerhardsa0 May 23, 2024
556eed4
code cov doesnt use the warn
Gerhardsa0 May 23, 2024
57b1305
code cov doesnt use the warn
Gerhardsa0 May 23, 2024
daa766c
linter fixes
Gerhardsa0 May 23, 2024
4213af3
style: apply automated linter fixes
megalinter-bot May 23, 2024
b766c63
test should work
Gerhardsa0 May 23, 2024
5e9da42
Merge remote-tracking branch 'origin/765-feat-add-temporal-operations…
Gerhardsa0 May 23, 2024
6131534
style: apply automated linter fixes
megalinter-bot May 23, 2024
920125c
test should work
Gerhardsa0 May 23, 2024
b433180
Merge remote-tracking branch 'origin/765-feat-add-temporal-operations…
Gerhardsa0 May 23, 2024
abb5cd3
test should work
Gerhardsa0 May 23, 2024
ac51634
fixing tests
Gerhardsa0 May 23, 2024
13d19d7
fixing tests
Gerhardsa0 May 23, 2024
b3bc80f
style: apply automated linter fixes
megalinter-bot May 23, 2024
c82e78e
fixing tests
Gerhardsa0 May 24, 2024
391141b
Merge remote-tracking branch 'origin/765-feat-add-temporal-operations…
Gerhardsa0 May 24, 2024
0165394
fixing tests
Gerhardsa0 May 24, 2024
51d7a15
added self written format checker
Gerhardsa0 May 24, 2024
2ecaff7
linter fixes
Gerhardsa0 May 24, 2024
f8db6be
style: apply automated linter fixes
megalinter-bot May 24, 2024
228c8c6
fixed doc build
Gerhardsa0 May 24, 2024
928d22b
Merge remote-tracking branch 'origin/765-feat-add-temporal-operations…
Gerhardsa0 May 24, 2024
6937d2c
fixed doc build
Gerhardsa0 May 24, 2024
536e16f
Merge branch 'main' of https://github.com/Safe-DS/Library into 765-fe…
Gerhardsa0 May 29, 2024
adc041e
removed time_name from time_series dataset
Gerhardsa0 May 29, 2024
97ac579
linter changes
Gerhardsa0 May 29, 2024
9468b4a
Merge branch 'main' into 765-feat-add-temporal-operations
Gerhardsa0 May 29, 2024
98746db
style: apply automated linter fixes
megalinter-bot May 29, 2024
5ed4186
style: apply automated linter fixes
megalinter-bot May 29, 2024
1c67a0d
fixed docs
Gerhardsa0 May 29, 2024
4d35801
Merge remote-tracking branch 'origin/765-feat-add-temporal-operations…
Gerhardsa0 May 29, 2024
9443c21
fixed docs
Gerhardsa0 May 29, 2024
d39a737
fixed docs
Gerhardsa0 May 29, 2024
d28436b
fixed code cov
Gerhardsa0 May 31, 2024
1b83eb2
fixed linter
Gerhardsa0 May 31, 2024
3eb9d13
added temporal operations
Gerhardsa0 Jun 10, 2024
d59628b
Merge branch 'main' of https://github.com/Safe-DS/Library into 765-fe…
Gerhardsa0 Jun 10, 2024
c89865e
fixed comments
Gerhardsa0 Jun 10, 2024
c5a2119
style: apply automated linter fixes
megalinter-bot Jun 10, 2024
55c507b
style: apply automated linter fixes
megalinter-bot Jun 10, 2024
a030244
fixed comments
Gerhardsa0 Jun 10, 2024
bc5a0a0
Merge remote-tracking branch 'origin/765-feat-add-temporal-operations…
Gerhardsa0 Jun 10, 2024
94b4de1
fixed comments
Gerhardsa0 Jun 10, 2024
61200a4
Update src/safeds/data/tabular/containers/_temporal_cell.py
Gerhardsa0 Jun 10, 2024
3e7ced4
Update src/safeds/data/tabular/containers/_temporal_cell.py
Gerhardsa0 Jun 10, 2024
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
18 changes: 18 additions & 0 deletions src/safeds/data/tabular/containers/_lazy_temporal_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ def __sizeof__(self) -> int:
# Temporal operations
# ------------------------------------------------------------------------------------------------------------------

def century(self) -> Cell[int]:
return _LazyCell(self._expression.dt.century())

def weekday(self) -> Cell[int]:
return _LazyCell(self._expression.dt.weekday())

def week(self) -> Cell[int]:
return _LazyCell(self._expression.dt.week())

def year(self) -> Cell[int]:
return _LazyCell(self._expression.dt.year())

def month(self) -> Cell[int]:
return _LazyCell(self._expression.dt.month())

def day(self) -> Cell[int]:
return _LazyCell(self._expression.dt.day())

def datetime_to_string(self, format_string: str = "%Y/%m/%d %H:%M:%S") -> Cell[str]:
if not _check_format_string(format_string):
raise ValueError("Invalid format string")
Expand Down
151 changes: 146 additions & 5 deletions src/safeds/data/tabular/containers/_temporal_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@

class TemporalCell(ABC):
"""
A class that contains temporal methods for a column.
Namespace for operations on temporal data.

Parameters
----------
column:
The column to be operated on.
This class cannot be instantiated directly. It can only be accessed using the `dt` attribute of a cell.

Examples
--------
Expand All @@ -31,6 +28,150 @@ class TemporalCell(ABC):
+------------+
"""

@abstractmethod
def century(self) -> Cell[int]:
"""
Get the weekday of the underlying date(time) data.
Gerhardsa0 marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
A cell containing the weekday as integer.
Gerhardsa0 marked this conversation as resolved.
Show resolved Hide resolved

Examples
--------
>>> from safeds.data.tabular.containers import Column
>>> import datetime
>>> column = Column("example", [datetime.date(2022, 1, 1)])
>>> column.transform(lambda cell: cell.dt.century())
+---------+
| example |
| --- |
| i32 |
+=========+
| 21 |
+---------+
"""

@abstractmethod
def weekday(self) -> Cell[int]:
"""
Get the weekday of the underlying date(time) data.

Returns
-------
A cell containing the weekday as integer.

Examples
--------
>>> from safeds.data.tabular.containers import Column
>>> import datetime
>>> column = Column("example", [datetime.date(2022, 1, 1)])
>>> column.transform(lambda cell: cell.dt.weekday())
+---------+
| example |
| --- |
| i8 |
+=========+
| 6 |
+---------+
"""

@abstractmethod
def week(self) -> Cell[int]:
"""
Get the week of the underlying date(time) data.

Returns
-------
A cell containing the week as integer.

Examples
--------
>>> from safeds.data.tabular.containers import Column
>>> import datetime
>>> column = Column("example", [datetime.date(2022, 1, 1)])
>>> column.transform(lambda cell: cell.dt.week())
+---------+
| example |
| --- |
| i8 |
+=========+
| 52 |
+---------+
"""

@abstractmethod
def year(self) -> Cell[int]:
"""
Get the year of the underlying date(time) data.

Returns
-------
A cell containing the year as integer.

Examples
--------
>>> from safeds.data.tabular.containers import Column
>>> import datetime
>>> column = Column("example", [datetime.date(2022, 1, 9)])
>>> column.transform(lambda cell: cell.dt.year())
+---------+
| example |
| --- |
| i32 |
+=========+
| 2022 |
+---------+
"""

@abstractmethod
def month(self) -> Cell[int]:
"""
Get the month of the underlying date(time) data.

Returns
-------
A cell containing the month as integer.

Examples
--------
>>> from safeds.data.tabular.containers import Column
>>> import datetime
>>> column = Column("example", [datetime.date(2022, 1, 9)])
>>> column.transform(lambda cell: cell.dt.month())
+---------+
| example |
| --- |
| i8 |
+=========+
| 1 |
+---------+
"""

@abstractmethod
def day(self) -> Cell[int]:
"""
Get the day of the underlying date(time) data.

Returns
-------
A cell containing the day as integer.

Examples
--------
>>> from safeds.data.tabular.containers import Column
>>> import datetime
>>> column = Column("example", [datetime.date(2022, 1, 9)])
>>> column.transform(lambda cell: cell.dt.day())
+---------+
| example |
| --- |
| i8 |
+=========+
| 9 |
+---------+
"""

@abstractmethod
def datetime_to_string(self, format_string: str = "%Y/%m/%d %H:%M:%S") -> Cell[str]:
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import datetime

import pytest

from tests.helpers import assert_cell_operation_works


@pytest.mark.parametrize(
("expected", "input_date"),
[
(18, datetime.datetime(1800, 1, 9, 23, 29, 1, tzinfo=datetime.UTC)),
(21, datetime.date(2022, 1, 1)),
],
ids=[
"ISO datetime",
"ISO date",
],
)
def test_get_day(input_date: datetime.date, expected: bool) -> None:
assert_cell_operation_works(input_date, lambda cell: cell.dt.century(), expected)
20 changes: 20 additions & 0 deletions tests/safeds/data/tabular/containers/_temporal_cell/test_day.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import datetime

import pytest

from tests.helpers import assert_cell_operation_works


@pytest.mark.parametrize(
("expected", "input_date"),
[
(9, datetime.datetime(2022, 1, 9, 23, 29, 1, tzinfo=datetime.UTC)),
(1, datetime.date(2022, 1, 1)),
],
ids=[
"ISO datetime",
"ISO date",
],
)
def test_get_day(input_date: datetime.date, expected: bool) -> None:
assert_cell_operation_works(input_date, lambda cell: cell.dt.day(), expected)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import datetime

import pytest

from tests.helpers import assert_cell_operation_works


@pytest.mark.parametrize(
("expected", "input_date"),
[
(3, datetime.datetime(2022, 3, 9, 23, 29, 1, tzinfo=datetime.UTC)),
(1, datetime.date(2022, 1, 1)),
],
ids=[
"ISO datetime",
"ISO date",
],
)
def test_get_month(input_date: datetime.date, expected: bool) -> None:
assert_cell_operation_works(input_date, lambda cell: cell.dt.month(), expected)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import datetime

import pytest

from tests.helpers import assert_cell_operation_works


@pytest.mark.parametrize(
("expected", "input_date"),
[
(10, datetime.datetime(2023, 3, 9, 23, 29, 1, tzinfo=datetime.UTC)),
(52, datetime.date(2022, 1, 1)),
],
ids=[
"ISO datetime",
"ISO date",
],
)
def test_get_week(input_date: datetime.date, expected: bool) -> None:
assert_cell_operation_works(input_date, lambda cell: cell.dt.week(), expected)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import datetime

import pytest

from tests.helpers import assert_cell_operation_works


@pytest.mark.parametrize(
("expected", "input_date"),
[
(4, datetime.datetime(2023, 3, 9, 23, 29, 1, tzinfo=datetime.UTC)),
(6, datetime.date(2022, 1, 1)),
],
ids=[
"ISO datetime",
"ISO date",
],
)
def test_get_weekday(input_date: datetime.date, expected: bool) -> None:
assert_cell_operation_works(input_date, lambda cell: cell.dt.weekday(), expected)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import datetime

import pytest

from tests.helpers import assert_cell_operation_works


@pytest.mark.parametrize(
("expected", "input_date"),
[
(2023, datetime.datetime(2023, 3, 9, 23, 29, 1, tzinfo=datetime.UTC)),
(2022, datetime.date(2022, 1, 1)),
],
ids=[
"ISO datetime",
"ISO date",
],
)
def test_get_year(input_date: datetime.date, expected: bool) -> None:
assert_cell_operation_works(input_date, lambda cell: cell.dt.year(), expected)