-
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: Added
Table.plot_boxplots
to plot a boxplot for each numerica…
…l column in the table (#254) Closes #156. ### Summary of Changes Added `Table.plot_boxplots` to plot a boxplot for each numerical column in the table Changed `Column.plot_boxplot` to set the title instead of the xlabel to match `Table.plot_boxplots` ### Additional Context Waiting for #239 -> Needed to add tests for `Table.plot_boxplots` --------- Co-authored-by: sibre28 <[email protected]> Co-authored-by: alex-senger <[email protected]> Co-authored-by: megalinter-bot <[email protected]> Co-authored-by: Lars Reimann <[email protected]>
- Loading branch information
1 parent
e27d410
commit 0203a0c
Showing
10 changed files
with
102 additions
and
2 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12 KB
tests/resources/image/snapshot_boxplots/four_columns_some_non_numeric.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
37 changes: 37 additions & 0 deletions
37
tests/safeds/data/tabular/containers/_table/test_plot_boxplots.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,37 @@ | ||
import pytest | ||
from safeds.data.image.containers import Image | ||
from safeds.data.tabular.containers import Table | ||
from safeds.exceptions import NonNumericColumnError | ||
|
||
from tests.helpers import resolve_resource_path | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("table", "path"), | ||
[ | ||
(Table({"A": [1, 2, 3]}), "./image/snapshot_boxplots/one_column.png"), | ||
( | ||
Table({"A": [1, 2, 3], "B": ["A", "A", "Bla"], "C": [True, True, False], "D": [1.0, 2.1, 4.5]}), | ||
"./image/snapshot_boxplots/four_columns_some_non_numeric.png", | ||
), | ||
( | ||
Table({"A": [1, 2, 3], "B": [1.0, 2.1, 4.5], "C": [1, 2, 3], "D": [1.0, 2.1, 4.5]}), | ||
"./image/snapshot_boxplots/four_columns_all_numeric.png", | ||
), | ||
], | ||
ids=["one column", "four columns (some non-numeric)", "four columns (all numeric)"], | ||
) | ||
def test_should_match_snapshot(table: Table, path: str) -> None: | ||
current = table.plot_boxplots() | ||
current.to_png_file(resolve_resource_path(path)) | ||
snapshot = Image.from_png_file(resolve_resource_path(path)) | ||
|
||
# Inlining the expression into the assert causes pytest to hang if the assertion fails when run from PyCharm. | ||
assertion = snapshot._image.tobytes() == current._image.tobytes() | ||
assert assertion | ||
|
||
|
||
def test_should_raise_if_column_contains_non_numerical_values() -> None: | ||
table = Table.from_dict({"A": ["1", "2", "3.5"], "B": ["0.2", "4", "77"]}) | ||
with pytest.raises(NonNumericColumnError): | ||
table.plot_boxplots() |
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