-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: return the correct size for custom container objects (#547)
Summary: - feat: return the correct size for custom container objects This is needed to correctly evaluate whether an object is worth memoizing or keeping in the cache. See for context: Safe-DS/Runner#51 and Safe-DS/Runner#44 For future container classes (like e.g. image set this would also need to be added, to be compatible with the memoizing implementation in the runner)
- Loading branch information
Showing
14 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tests/safeds/data/tabular/containers/_column/test_sizeof.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import sys | ||
|
||
import pytest | ||
from safeds.data.tabular.containers import Column | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"column", | ||
[ | ||
Column("a", []), | ||
Column("a", [0]), | ||
Column("a", [0, "1"]), | ||
], | ||
ids=[ | ||
"empty", | ||
"one row", | ||
"multiple rows", | ||
], | ||
) | ||
def test_should_size_be_greater_than_normal_object(column: Column) -> None: | ||
assert sys.getsizeof(column) > sys.getsizeof(object()) |
39 changes: 39 additions & 0 deletions
39
tests/safeds/data/tabular/containers/_table/_tagged_table/_time_series/test_sizeof.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import sys | ||
|
||
import pytest | ||
from safeds.data.tabular.containers import Table, TimeSeries | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"time_series", | ||
[ | ||
TimeSeries( | ||
{ | ||
"time": [0, 1, 2], | ||
"feature_1": [3, 9, 6], | ||
"feature_2": [6, 12, 9], | ||
"target": [1, 3, 2], | ||
}, | ||
"target", | ||
"time", | ||
["feature_1", "feature_2"], | ||
), | ||
TimeSeries( | ||
{ | ||
"time": [0, 1, 2], | ||
"feature_1": [3, 9, 6], | ||
"feature_2": [6, 12, 9], | ||
"other": [3, 9, 12], | ||
"target": [1, 3, 2], | ||
}, | ||
"target", | ||
"time", | ||
["feature_1", "feature_2"], | ||
), | ||
], | ||
ids=["normal", "table_with_column_as_non_feature"], | ||
) | ||
def test_should_size_be_greater_than_normal_object(time_series: TimeSeries) -> None: | ||
assert sys.getsizeof(time_series) > sys.getsizeof(object()) |
35 changes: 35 additions & 0 deletions
35
tests/safeds/data/tabular/containers/_table/_tagged_table/test_sizeof.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import sys | ||
|
||
import pytest | ||
from safeds.data.tabular.containers import Table, TaggedTable | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"tagged_table", | ||
[ | ||
TaggedTable( | ||
{ | ||
"feature_1": [3, 9, 6], | ||
"feature_2": [6, 12, 9], | ||
"target": [1, 3, 2], | ||
}, | ||
"target", | ||
["feature_1", "feature_2"], | ||
), | ||
TaggedTable( | ||
{ | ||
"feature_1": [3, 9, 6], | ||
"feature_2": [6, 12, 9], | ||
"other": [3, 9, 12], | ||
"target": [1, 3, 2], | ||
}, | ||
"target", | ||
["feature_1", "feature_2"], | ||
), | ||
], | ||
ids=["normal", "table_with_column_as_non_feature"], | ||
) | ||
def test_should_size_be_greater_than_normal_object(tagged_table: TaggedTable) -> None: | ||
assert sys.getsizeof(tagged_table) > sys.getsizeof(object()) |
21 changes: 21 additions & 0 deletions
21
tests/safeds/data/tabular/containers/_table/test_sizeof.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import sys | ||
|
||
import pytest | ||
from safeds.data.tabular.containers import Table | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"table", | ||
[ | ||
Table(), | ||
Table({"col1": [0]}), | ||
Table({"col1": [0, "1"], "col2": ["a", "b"]}), | ||
], | ||
ids=[ | ||
"empty table", | ||
"table with one row", | ||
"table with multiple rows", | ||
], | ||
) | ||
def test_should_size_be_greater_than_normal_object(table: Table) -> None: | ||
assert sys.getsizeof(table) > sys.getsizeof(object()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters