-
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 'histogram_2d' in TablePlotter (#903)
Closes #869 ### Summary of Changes - added histogram_2d to TablePlotter - implemented darkmode like in #798 - added tests --------- Co-authored-by: megalinter-bot <[email protected]> Co-authored-by: gitgott1 <[email protected]> Co-authored-by: Lars Reimann <[email protected]>
- Loading branch information
1 parent
254617c
commit 4e65ba9
Showing
6 changed files
with
184 additions
and
1 deletion.
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
Binary file added
BIN
+10.8 KB
...__snapshots__/test_plot_histogram_2d/test_should_match_snapshot[functional].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
+9.21 KB
...g/__snapshots__/test_plot_histogram_2d/test_should_match_snapshot[multiple].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
+9.21 KB
..._snapshots__/test_plot_histogram_2d/test_should_match_snapshot[overlapping].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
+10.2 KB
...__/test_plot_histogram_2d/test_should_match_snapshot_dark_theme[dark_theme].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 101 additions & 0 deletions
101
tests/safeds/data/tabular/plotting/test_plot_histogram_2d.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,101 @@ | ||
import pytest | ||
from safeds.data.tabular.containers import Table | ||
from safeds.exceptions import ColumnNotFoundError, ColumnTypeError, OutOfBoundsError | ||
from syrupy import SnapshotAssertion | ||
|
||
from tests.helpers import os_mac, skip_if_os | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("table", "col1", "col2"), | ||
[ | ||
(Table({"A": [1, 2, 3], "B": [2, 4, 7]}), "A", "B"), | ||
( | ||
Table( | ||
{ | ||
"A": [1, 0.99, 0.99, 2], | ||
"B": [1, 0.99, 1.01, 2], | ||
}, | ||
), | ||
"A", | ||
"B", | ||
), | ||
( | ||
Table( | ||
{"A": [1, 0.99, 0.99, 2], "B": [1, 0.99, 1.01, 2], "C": [2, 2.99, 2.01, 3]}, | ||
), | ||
"A", | ||
"B", | ||
), | ||
], | ||
ids=[ | ||
"functional", | ||
"overlapping", | ||
"multiple", | ||
], | ||
) | ||
def test_should_match_snapshot( | ||
table: Table, | ||
col1: str, | ||
col2: str, | ||
snapshot_png_image: SnapshotAssertion, | ||
) -> None: | ||
skip_if_os([os_mac]) | ||
histogram_2d = table.plot.histogram_2d(col1, col2) | ||
assert histogram_2d == snapshot_png_image | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("table", "col1", "col2"), | ||
[ | ||
(Table({"A": [1, 2, 3], "B": [2, 4, 7]}), "C", "A"), | ||
(Table({"A": [1, 2, 3], "B": [2, 4, 7]}), "B", "C"), | ||
(Table({"A": [1, 2, 3], "B": [2, 4, 7]}), "C", "D"), | ||
(Table(), "C", "D"), | ||
], | ||
ids=[ | ||
"First argument doesn't exist", | ||
"Second argument doesn't exist", | ||
"Both arguments do not exist", | ||
"empty", | ||
], | ||
) | ||
def test_should_raise_if_column_does_not_exist(table: Table, col1: str, col2: str) -> None: | ||
with pytest.raises(ColumnNotFoundError): | ||
table.plot.histogram_2d(col1, col2) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("table", "col1", "col2"), | ||
[ | ||
(Table({"A": [1, 2, 3], "B": [2, 4, 7]}), "A", "B"), | ||
], | ||
ids=["dark_theme"], | ||
) | ||
def test_should_match_snapshot_dark_theme( | ||
table: Table, | ||
col1: str, | ||
col2: str, | ||
snapshot_png_image: SnapshotAssertion, | ||
) -> None: | ||
skip_if_os([os_mac]) | ||
histogram_2d = table.plot.histogram_2d(col1, col2, theme="dark") | ||
assert histogram_2d == snapshot_png_image | ||
|
||
|
||
def test_should_raise_if_value_not_in_range_x() -> None: | ||
table = Table({"col1": [1, 2, 1], "col2": [1, 2, 4]}) | ||
with pytest.raises(OutOfBoundsError): | ||
table.plot.histogram_2d("col1", "col2", x_max_bin_count=0) | ||
|
||
|
||
def test_should_raise_if_value_not_in_range_y() -> None: | ||
table = Table({"col1": [1, 2, 1], "col2": [1, 2, 4]}) | ||
with pytest.raises(OutOfBoundsError): | ||
table.plot.histogram_2d("col1", "col2", y_max_bin_count=0) | ||
|
||
|
||
def test_should_raise_if_column_is_not_numeric() -> None: | ||
table = Table({"col1": ["a"], "col2": ["b"]}) | ||
with pytest.raises(ColumnTypeError): | ||
table.plot.histogram_2d("col1", "col2") |