Skip to content

Commit 73cdfb1

Browse files
Gerhardsa0sibre28megalinter-botMarsmaennchen221
authored
feat: class for time series (#508)
Closes #481 ### Summary of Changes <!-- Please provide a summary of changes in this pull request, ensuring all changes are explained. --> added the time series class, with all basic tests and functionalities so it can be used like a normal table or taggedtrable with an extra time column --------- Co-authored-by: Ettl<AndiWrp> Co-authored-by: Simon <s6snbreu@uni-bonn.de> Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Co-authored-by: Simon Breuer <86068340+sibre28@users.noreply.github.com> Co-authored-by: Alexander <47296670+Marsmaennchen221@users.noreply.github.com>
1 parent 0cfe80a commit 73cdfb1

36 files changed

+3827
-10
lines changed

src/safeds/data/tabular/containers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
from ._row import Row
55
from ._table import Table
66
from ._tagged_table import TaggedTable
7+
from ._time_series import TimeSeries
78

89
__all__ = [
910
"Column",
1011
"Row",
1112
"Table",
1213
"TaggedTable",
14+
"TimeSeries",
1315
]

src/safeds/data/tabular/containers/_table.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from safeds.data.tabular.transformation import InvertibleTableTransformer, TableTransformer
3737

3838
from ._tagged_table import TaggedTable
39+
from ._time_series import TimeSeries
3940

4041
# Enable copy-on-write for pandas dataframes
4142
pd.options.mode.copy_on_write = True
@@ -1715,6 +1716,43 @@ def tag_columns(self, target_name: str, feature_names: list[str] | None = None)
17151716

17161717
return TaggedTable._from_table(self, target_name, feature_names)
17171718

1719+
def time_columns(self, target_name: str, time_name: str, feature_names: list[str] | None = None) -> TimeSeries:
1720+
"""
1721+
Return a new `TimeSeries` with columns marked as a target and time column or feature columns.
1722+
1723+
The original table is not modified.
1724+
1725+
Parameters
1726+
----------
1727+
target_name : str
1728+
Name of the target column.
1729+
time_name : str
1730+
Name of the time column.
1731+
feature_names : list[str] | None
1732+
Names of the feature columns. If None, all columns except the target and time columns are used.
1733+
1734+
Returns
1735+
-------
1736+
time_series : TimeSeries
1737+
A new time series with the given target, time and feature names.
1738+
1739+
Raises
1740+
------
1741+
ValueError
1742+
If the target column is also a feature column.
1743+
ValueError
1744+
If there is no other column than the specified target and time columns left to be a feature column
1745+
1746+
Examples
1747+
--------
1748+
>>> from safeds.data.tabular.containers import Table, TimeSeries
1749+
>>> table = Table.from_dict({"time": ["01.01", "01.02", "01.03"], "price": [1.10, 1.19, 1.79], "amount_bought": [74, 72, 51]})
1750+
>>> tagged_table = table.time_columns(target_name="amount_bought",time_name = "time", feature_names=["price"])
1751+
"""
1752+
from ._time_series import TimeSeries
1753+
1754+
return TimeSeries._from_table_to_time_series(self, target_name, time_name, feature_names)
1755+
17181756
def transform_column(self, name: str, transformer: Callable[[Row], Any]) -> Table:
17191757
"""
17201758
Return a new `Table` with the provided column transformed by calling the provided transformer.

src/safeds/data/tabular/containers/_tagged_table.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def add_row(self, row: Row) -> TaggedTable:
350350
Returns
351351
-------
352352
table : TaggedTable
353-
A new table with the added row at the end.
353+
A new tagged table with the added row at the end.
354354
355355
Raises
356356
------
@@ -373,7 +373,7 @@ def add_rows(self, rows: list[Row] | Table) -> TaggedTable:
373373
Returns
374374
-------
375375
result : TaggedTable
376-
A new table which combines the original table and the given rows.
376+
A new tagged table which combines the original table and the given rows.
377377
378378
Raises
379379
------
@@ -386,7 +386,7 @@ def filter_rows(self, query: Callable[[Row], bool]) -> TaggedTable:
386386
"""
387387
Return a new `TaggedTable` containing only rows that match the given Callable (e.g. lambda function).
388388
389-
The original table is not modified.
389+
The original tagged table is not modified.
390390
391391
Parameters
392392
----------
@@ -395,8 +395,8 @@ def filter_rows(self, query: Callable[[Row], bool]) -> TaggedTable:
395395
396396
Returns
397397
-------
398-
table : TaggedTable
399-
A table containing only the rows to match the query.
398+
result : TaggedTable
399+
A new tagged table containing only the rows to match the query.
400400
"""
401401
return TaggedTable._from_table(
402402
super().filter_rows(query),

0 commit comments

Comments
 (0)