Skip to content

Commit ca23f0f

Browse files
feat: when using from table to time series feature must be given (#572)
Closes #571 ### Summary of Changes TimeSeries no longer is subclass of TaggedTable only of Table <!-- Please provide a summary of changes in this pull request, ensuring all changes are explained. --> --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
1 parent f6a3ca7 commit ca23f0f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+486
-515
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
22

3-
import sys
43
import functools
54
import io
5+
import sys
66
import warnings
77
from pathlib import Path
88
from typing import TYPE_CHECKING, Any, TypeVar
@@ -1774,7 +1774,7 @@ def time_columns(self, target_name: str, time_name: str, feature_names: list[str
17741774
"""
17751775
from ._time_series import TimeSeries
17761776

1777-
return TimeSeries._from_table_to_time_series(self, target_name, time_name, feature_names)
1777+
return TimeSeries._from_table(self, target_name, time_name, feature_names)
17781778

17791779
def transform_column(self, name: str, transformer: Callable[[Row], Any]) -> Table:
17801780
"""

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

Lines changed: 196 additions & 163 deletions
Large diffs are not rendered by default.

tests/helpers/_assertions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def assert_that_time_series_are_equal(table1: TimeSeries, table2: TimeSeries) ->
5353
The timeseries to compare the first timeseries to.
5454
"""
5555
assert table1.schema == table2.schema
56-
assert table1.features == table2.features
57-
assert table1.target == table2.target
56+
assert table1._feature_names == table2._feature_names
57+
assert table1.features == table2._features
58+
assert table1.target == table2._target
5859
assert table1.time == table2.time
5960
assert table1 == table2

tests/safeds/data/tabular/containers/_table/_tagged_table/_time_series/test_eq.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

tests/safeds/data/tabular/containers/_table/_tagged_table/_time_series/test_hash.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/safeds/data/tabular/containers/_table/_tagged_table/_time_series/test_sizeof.py

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
target_name="target",
3030
time_name="time",
31-
feature_names=["feature_1"],
31+
feature_names=None,
3232
),
3333
),
3434
],
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"target",
3131
"time",
32-
["feature_1"],
32+
None,
3333
),
3434
),
3535
],
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
from typing import Any
2+
3+
import pytest
4+
from safeds.data.tabular.containers import Row, Table, TaggedTable, TimeSeries
5+
6+
7+
@pytest.mark.parametrize(
8+
("table1", "table2", "expected"),
9+
[
10+
(
11+
TimeSeries({"a": [], "b": [], "c": []}, "b", "c", ["a"]),
12+
TimeSeries({"a": [], "b": [], "c": []}, "b", "c", ["a"]),
13+
True,
14+
),
15+
(
16+
TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}, "b", "c", ["a"]),
17+
TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}, "b", "c", ["a"]),
18+
True,
19+
),
20+
(
21+
TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9], "d": [10, 11, 12]}, "b", "d", ["a"]),
22+
TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9], "d": [10, 11, 12]}, "c", "d", ["a"]),
23+
False,
24+
),
25+
(
26+
TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9], "d": [10, 11, 12]}, "b", "c", ["a"]),
27+
TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9], "e": [10, 11, 12]}, "b", "c", ["a"]),
28+
False,
29+
),
30+
(
31+
TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}, "b", "c", ["a"]),
32+
TimeSeries({"a": [1, 1, 3], "b": [4, 5, 6], "c": [7, 8, 9]}, "b", "c", ["a"]),
33+
False,
34+
),
35+
(
36+
TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}, "b", "c", ["a"]),
37+
TimeSeries({"a": ["1", "2", "3"], "b": [4, 5, 6], "c": [7, 8, 9]}, "b", "c", ["a"]),
38+
False,
39+
),
40+
(
41+
TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9], "d": [10, 11, 12]}, "b", "d", ["a"]),
42+
TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9], "d": [10, 11, 12]}, "b", "d", ["c"]),
43+
False,
44+
),
45+
(
46+
TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9], "d": [10, 11, 12]}, "b", "d", ["a"]),
47+
TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9], "d": [10, 11, 12]}, "b", "c", ["a"]),
48+
False,
49+
),
50+
],
51+
ids=[
52+
"rowless table",
53+
"equal tables",
54+
"different target",
55+
"different column names",
56+
"different values",
57+
"different types",
58+
"different features",
59+
"different time",
60+
],
61+
)
62+
def test_should_return_whether_two_tagged_tables_are_equal(
63+
table1: TimeSeries,
64+
table2: TimeSeries,
65+
expected: bool,
66+
) -> None:
67+
assert (table1.__eq__(table2)) == expected
68+
69+
70+
@pytest.mark.parametrize(
71+
"table1",
72+
[TimeSeries({"a": [], "b": [], "c": []}, "b", "c", ["a"])],
73+
ids=[
74+
"any",
75+
],
76+
)
77+
def test_should_return_true_if_objects_are_identical(table1: TimeSeries) -> None:
78+
assert (table1.__eq__(table1)) is True
79+
80+
81+
@pytest.mark.parametrize(
82+
("table", "other"),
83+
[
84+
(TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}, "b", "c", ["a"]), None),
85+
(TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}, "b", "c", ["a"]), Row()),
86+
(TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}, "b", "c", ["a"]), Table()),
87+
(
88+
TimeSeries({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}, "b", "c", ["a"]),
89+
TaggedTable({"a": [1, 2, 3], "b": [4, 5, 6]}, "b", ["a"]),
90+
),
91+
],
92+
ids=[
93+
"TimeSeries vs. None",
94+
"TimeSeries vs. Row",
95+
"TimeSeries vs. Table",
96+
"TimeSeries vs. TaggedTable",
97+
],
98+
)
99+
def test_should_return_not_implemented_if_other_is_not_tagged_table(table: TimeSeries, other: Any) -> None:
100+
assert (table.__eq__(other)) is NotImplemented
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
target_name="T",
1818
time_name="time",
19+
feature_names=["A", "B", "C"],
1920
),
2021
Table({"A": [1, 4], "B": [2, 5], "C": [3, 6]}),
2122
),
Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -52,36 +52,7 @@
5252
"time",
5353
["A", "B", "C"],
5454
ValueError,
55-
r"Column 'A' cannot be both feature and target.",
56-
),
57-
(
58-
Table(
59-
{
60-
"time": [0, 1],
61-
"A": [1, 4],
62-
"B": [2, 5],
63-
"C": [3, 6],
64-
"T": [0, 1],
65-
},
66-
),
67-
"A",
68-
"time",
69-
[],
70-
ValueError,
71-
r"At least one feature column must be specified.",
72-
),
73-
(
74-
Table(
75-
{
76-
"time": [0, 1],
77-
"A": [1, 4],
78-
},
79-
),
80-
"A",
81-
"time",
82-
None,
83-
ValueError,
84-
r"At least one feature column must be specified.",
55+
r"Column 'A' can not be target and feature column.",
8556
),
8657
(
8758
Table(
@@ -120,8 +91,6 @@
12091
"feature_does_not_exist",
12192
"target_does_not_exist",
12293
"target_and_feature_overlap",
123-
"features_are_empty-explicitly",
124-
"features_are_empty_implicitly",
12594
"time_does_not_exist",
12695
"time_is_also_feature",
12796
],
@@ -135,7 +104,7 @@ def test_should_raise_error(
135104
error_msg: str,
136105
) -> None:
137106
with pytest.raises(error, match=error_msg):
138-
TimeSeries._from_table_to_time_series(
107+
TimeSeries._from_table(
139108
table,
140109
target_name=target_name,
141110
time_name=time_name,
@@ -186,7 +155,7 @@ def test_should_raise_error(
186155
),
187156
"T",
188157
"time",
189-
None,
158+
["B"],
190159
),
191160
],
192161
ids=["create_tagged_table", "tagged_table_not_all_columns_are_features", "tagged_table_with_feature_names_as_None"],
@@ -197,7 +166,7 @@ def test_should_create_a_tagged_table(
197166
time_name: str,
198167
feature_names: list[str] | None,
199168
) -> None:
200-
time_series = TimeSeries._from_table_to_time_series(
169+
time_series = TimeSeries._from_table(
201170
table,
202171
target_name=target_name,
203172
time_name=time_name,

0 commit comments

Comments
 (0)