-
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: add
_file
suffix to methods interacting with files (#103)
### Summary of Changes In `Table`: * Rename `to_csv` to `to_csv_file` * Rename `to_json` to `to_json_file` * Rename `from_csv` to `from_csv_file` * Rename `from_json` to `from_json_file` * Rename `path_to_file` parameters to `path` --------- Co-authored-by: lars-reimann <[email protected]>
- Loading branch information
1 parent
3931ce9
commit ec011e4
Showing
46 changed files
with
156 additions
and
134 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
File renamed without changes.
File renamed without changes.
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
18 changes: 18 additions & 0 deletions
18
tests/safeds/data/tabular/containers/_table/test_from_csv_file.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,18 @@ | ||
import pytest | ||
from safeds.data.tabular.containers import Table | ||
from tests.fixtures import resolve_resource_path | ||
|
||
|
||
def test_from_csv_file_valid() -> None: | ||
table = Table.from_csv_file(resolve_resource_path("test_table_from_csv_file.csv")) | ||
assert ( | ||
table.get_column("A").get_value(0) == 1 | ||
and table.get_column("B").get_value(0) == 2 | ||
) | ||
|
||
|
||
def test_from_csv_file_invalid() -> None: | ||
with pytest.raises(FileNotFoundError): | ||
Table.from_csv_file( | ||
resolve_resource_path("test_table_from_csv_file_invalid.csv") | ||
) |
20 changes: 20 additions & 0 deletions
20
tests/safeds/data/tabular/containers/_table/test_from_json_file.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,20 @@ | ||
import pytest | ||
from safeds.data.tabular.containers import Table | ||
from tests.fixtures import resolve_resource_path | ||
|
||
|
||
def test_from_json_file_valid() -> None: | ||
table = Table.from_json_file( | ||
resolve_resource_path("test_table_from_json_file.json") | ||
) | ||
assert ( | ||
table.get_column("A").get_value(0) == 1 | ||
and table.get_column("B").get_value(0) == 2 | ||
) | ||
|
||
|
||
def test_from_json_file_invalid() -> None: | ||
with pytest.raises(FileNotFoundError): | ||
Table.from_json_file( | ||
resolve_resource_path("test_table_from_json_file_invalid.json") | ||
) |
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
16 changes: 0 additions & 16 deletions
16
tests/safeds/data/tabular/containers/_table/test_read_csv.py
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
tests/safeds/data/tabular/containers/_table/test_read_json.py
This file was deleted.
Oops, something went wrong.
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
15 changes: 15 additions & 0 deletions
15
tests/safeds/data/tabular/containers/_table/test_to_csv_file.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,15 @@ | ||
from tempfile import NamedTemporaryFile | ||
|
||
import pandas as pd | ||
from safeds.data.tabular.containers import Table | ||
|
||
|
||
def test_to_csv_file() -> None: | ||
table = Table(pd.DataFrame(data={"col1": ["col1_1"], "col2": ["col2_1"]})) | ||
with NamedTemporaryFile() as tmp_table_file: | ||
tmp_table_file.close() | ||
with open(tmp_table_file.name, "w", encoding="utf-8") as tmp_file: | ||
table.to_csv_file(tmp_file.name) | ||
with open(tmp_table_file.name, "r", encoding="utf-8") as tmp_file: | ||
table_r = Table.from_csv_file(tmp_file.name) | ||
assert table == table_r |
15 changes: 15 additions & 0 deletions
15
tests/safeds/data/tabular/containers/_table/test_to_json_file.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,15 @@ | ||
from tempfile import NamedTemporaryFile | ||
|
||
import pandas as pd | ||
from safeds.data.tabular.containers import Table | ||
|
||
|
||
def test_to_json_file() -> None: | ||
table = Table(pd.DataFrame(data={"col1": ["col1_1"], "col2": ["col2_1"]})) | ||
with NamedTemporaryFile() as tmp_table_file: | ||
tmp_table_file.close() | ||
with open(tmp_table_file.name, "w", encoding="utf-8") as tmp_file: | ||
table.to_json_file(tmp_file.name) | ||
with open(tmp_table_file.name, "r", encoding="utf-8") as tmp_file: | ||
table_r = Table.from_json_file(tmp_file.name) | ||
assert table == table_r |
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
Oops, something went wrong.