-
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.
Closes #867 ### Summary of Changes This pull request applies the changes, which implement violin plots for tables and columns, while also adding corresponding tests as well as adding a section in data_visualization.ipynb. --------- Co-authored-by: megalinter-bot <[email protected]> Co-authored-by: Lars Reimann <[email protected]>
- Loading branch information
1 parent
5a0cdb3
commit 9f5992a
Showing
23 changed files
with
320 additions
and
19 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Binary file added
BIN
+8.6 KB
.../__snapshots__/test_plot_violin_plot/test_should_match_dark_snapshot[empty].png
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
...hots__/test_plot_violin_plot/test_should_match_dark_snapshot[multiple rows].png
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
+8.32 KB
..._snapshots__/test_plot_violin_plot/test_should_match_dark_snapshot[one row].png
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
+8.95 KB
...olumn/__snapshots__/test_plot_violin_plot/test_should_match_snapshot[empty].png
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
+11.9 KB
...snapshots__/test_plot_violin_plot/test_should_match_snapshot[multiple rows].png
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
+8.56 KB
...umn/__snapshots__/test_plot_violin_plot/test_should_match_snapshot[one row].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions
46
tests/safeds/data/tabular/containers/_column/test_plot_violin_plot.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,46 @@ | ||
import pytest | ||
from safeds.data.tabular.containers import Column | ||
from safeds.exceptions import ColumnTypeError | ||
from syrupy import SnapshotAssertion | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"column", | ||
[ | ||
Column("a", []), | ||
Column("a", [0]), | ||
Column("a", [0, 1]), | ||
], | ||
ids=[ | ||
"empty", | ||
"one row", | ||
"multiple rows", | ||
], | ||
) | ||
def test_should_match_snapshot(column: Column, snapshot_png_image: SnapshotAssertion) -> None: | ||
violin_plot = column.plot.violin_plot() | ||
assert violin_plot == snapshot_png_image | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"column", | ||
[ | ||
Column("a", []), | ||
Column("a", [0]), | ||
Column("a", [0, 1]), | ||
], | ||
ids=[ | ||
"empty", | ||
"one row", | ||
"multiple rows", | ||
], | ||
) | ||
def test_should_match_dark_snapshot(column: Column, snapshot_png_image: SnapshotAssertion) -> None: | ||
violin_plot = column.plot.violin_plot(theme="dark") | ||
assert violin_plot == snapshot_png_image | ||
|
||
|
||
def test_should_raise_if_column_contains_non_numerical_values() -> None: | ||
column = Column("a", ["A", "B", "C"]) | ||
with pytest.raises(ColumnTypeError): | ||
column.plot.violin_plot() |
Binary file added
BIN
+17.7 KB
...ot_violin_plots/test_should_match_dark_snapshot[four columns (all numeric)].png
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
+20.9 KB
...olin_plots/test_should_match_dark_snapshot[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.
Binary file added
BIN
+15.5 KB
...pshots__/test_plot_violin_plots/test_should_match_dark_snapshot[one column].png
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
+17.7 KB
...st_plot_violin_plots/test_should_match_snapshot[four columns (all numeric)].png
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
+20.9 KB
...ot_violin_plots/test_should_match_snapshot[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.
Binary file added
BIN
+15.4 KB
...__snapshots__/test_plot_violin_plots/test_should_match_snapshot[one column].png
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
+17.7 KB
...lot_violinplots/test_should_match_dark_snapshot[four columns (all numeric)].png
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
+20.9 KB
...iolinplots/test_should_match_dark_snapshot[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.
Binary file added
BIN
+15.5 KB
...apshots__/test_plot_violinplots/test_should_match_dark_snapshot[one column].png
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
+17.7 KB
...est_plot_violinplots/test_should_match_snapshot[four columns (all numeric)].png
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
+20.9 KB
...lot_violinplots/test_should_match_snapshot[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.
Binary file added
BIN
+15.4 KB
.../__snapshots__/test_plot_violinplots/test_should_match_snapshot[one column].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions
49
tests/safeds/data/tabular/plotting/test_plot_violin_plots.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,49 @@ | ||
import pytest | ||
from safeds.data.tabular.containers import Table | ||
from safeds.exceptions import NonNumericColumnError | ||
from syrupy import SnapshotAssertion | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"table", | ||
[ | ||
Table({"A": [1, 2, 3]}), | ||
Table({"A": [1, 2, 3], "B": ["A", "A", "Bla"], "C": [True, True, False], "D": [1.0, 2.1, 4.5]}), | ||
Table({"A": [1, 2, 3], "B": [1.0, 2.1, 4.5], "C": [1, 2, 3], "D": [1.0, 2.1, 4.5]}), | ||
], | ||
ids=["one column", "four columns (some non-numeric)", "four columns (all numeric)"], | ||
) | ||
def test_should_match_snapshot(table: Table, snapshot_png_image: SnapshotAssertion) -> None: | ||
violinplots = table.plot.violin_plots() | ||
assert violinplots == snapshot_png_image | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"table", | ||
[ | ||
Table({"A": [1, 2, 3]}), | ||
Table({"A": [1, 2, 3], "B": ["A", "A", "Bla"], "C": [True, True, False], "D": [1.0, 2.1, 4.5]}), | ||
Table({"A": [1, 2, 3], "B": [1.0, 2.1, 4.5], "C": [1, 2, 3], "D": [1.0, 2.1, 4.5]}), | ||
], | ||
ids=["one column", "four columns (some non-numeric)", "four columns (all numeric)"], | ||
) | ||
def test_should_match_dark_snapshot(table: Table, snapshot_png_image: SnapshotAssertion) -> None: | ||
violinplots = table.plot.violin_plots(theme="dark") | ||
assert violinplots == snapshot_png_image | ||
|
||
|
||
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, | ||
match=( | ||
r"Tried to do a numerical operation on one or multiple non-numerical columns: \nThis table contains only" | ||
r" non-numerical columns." | ||
), | ||
): | ||
table.plot.violin_plots() | ||
|
||
|
||
def test_should_fail_on_empty_table() -> None: | ||
with pytest.raises(NonNumericColumnError): | ||
Table().plot.violin_plots() |