-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Convert between Excel file and Table
#233
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
cdfd832
created methods for table from_excel_file() and to_excel_file()
PhilipGutberlet ac71a9f
replaced os.remove() with Path.unlink()
PhilipGutberlet b896252
style: apply automated linter fixes
megalinter-bot 6b72525
style: apply automated linter fixes
megalinter-bot c17106b
Merge branch 'main' of https://github.com/Safe-DS/Stdlib into 138-cre…
patrikguempel 2ec39a2
- to_excel_file() and from_excel_file() now also accept a path object
patrikguempel 95e8d29
resolved further comments
patrikguempel ef63bb7
Merge branch 'main' into 138-create-a-table-from-an-excel-file
PhilipGutberlet e38e447
fixed type annotation for test_to_excel_file.py and test_from_excel_f…
PhilipGutberlet 7305f53
style: apply automated linter fixes
megalinter-bot 15f9a50
removed unused imports
PhilipGutberlet 1d51383
Merge remote-tracking branch 'origin/138-create-a-table-from-an-excel…
PhilipGutberlet 8c61330
fixed keywords
patrikguempel 30ad2be
Merge remote-tracking branch 'origin/138-create-a-table-from-an-excel…
patrikguempel 9d93c13
build: recreate lock file
lars-reimann c7e801f
Merge branch 'main' into 138-create-a-table-from-an-excel-file
lars-reimann 06f9e87
test: compare entire tables
lars-reimann 466c854
docs: add comma
lars-reimann e3ef5d1
test: same structure as for other to_XY_file methods
lars-reimann 4df05d2
style: apply automated linter fixes
megalinter-bot e14f9b9
test: rename test
lars-reimann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
Binary file not shown.
40 changes: 40 additions & 0 deletions
40
tests/safeds/data/tabular/containers/_table/test_from_excel_file.py
This file contains hidden or 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,40 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from safeds.data.tabular.containers import Table | ||
|
|
||
| from tests.helpers import resolve_resource_path | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("path", "expected"), | ||
| [ | ||
| ( | ||
| resolve_resource_path("./dummy_excel_file.xlsx"), | ||
| Table.from_dict( | ||
| { | ||
| "A": [1], | ||
| "B": [2], | ||
| }, | ||
| ), | ||
| ), | ||
| ( | ||
| Path(resolve_resource_path("./dummy_excel_file.xlsx")), | ||
| Table.from_dict( | ||
| { | ||
| "A": [1], | ||
| "B": [2], | ||
| }, | ||
| ), | ||
| ), | ||
| ], | ||
| ids=["string path", "object path"], | ||
| ) | ||
| def test_should_create_table_from_excel_file(path: str | Path, expected: Table) -> None: | ||
| table = Table.from_excel_file(path) | ||
| assert table == expected | ||
|
|
||
|
|
||
| def test_should_raise_if_file_not_found() -> None: | ||
| with pytest.raises(FileNotFoundError): | ||
| Table.from_excel_file(resolve_resource_path("test_table_from_excel_file_invalid.xls")) |
26 changes: 26 additions & 0 deletions
26
tests/safeds/data/tabular/containers/_table/test_to_excel_file.py
This file contains hidden or 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,26 @@ | ||
| from pathlib import Path | ||
| from tempfile import NamedTemporaryFile | ||
|
|
||
| from safeds.data.tabular.containers import Table | ||
|
|
||
|
|
||
| def test_should_create_csv_file_from_table_by_str() -> None: | ||
| table = Table.from_dict({"col1": ["col1_1"], "col2": ["col2_1"]}) | ||
| with NamedTemporaryFile(suffix=".xlsx") as tmp_table_file: | ||
| tmp_table_file.close() | ||
| with Path(tmp_table_file.name).open("w", encoding="utf-8") as tmp_file: | ||
| table.to_excel_file(tmp_file.name) | ||
| with Path(tmp_table_file.name).open("r", encoding="utf-8") as tmp_file: | ||
| table_r = Table.from_excel_file(tmp_file.name) | ||
| assert table == table_r | ||
|
|
||
|
|
||
| def test_should_create_csv_file_from_table_by_path() -> None: | ||
| table = Table.from_dict({"col1": ["col1_1"], "col2": ["col2_1"]}) | ||
| with NamedTemporaryFile(suffix=".xlsx") as tmp_table_file: | ||
| tmp_table_file.close() | ||
| with Path(tmp_table_file.name).open("w", encoding="utf-8") as tmp_file: | ||
| table.to_excel_file(Path(tmp_file.name)) | ||
| with Path(tmp_table_file.name).open("r", encoding="utf-8") as tmp_file: | ||
| table_r = Table.from_excel_file(Path(tmp_file.name)) | ||
| assert table == table_r |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.