-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add moving average plot #836
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
30 commits
Select commit
Hold shift + click to select a range
9660618
added moving average plot
Gerhardsa0 dd7b388
added moving average plot
Gerhardsa0 547325a
linter change
Gerhardsa0 ce250b9
style: apply automated linter fixes
megalinter-bot 2eb7fc4
Merge branch 'main' into 521-feat-add-moving-average-plot-1
Gerhardsa0 9c882d9
for numerical columns the plot shows the values inbetween
Gerhardsa0 05fd84d
Merge remote-tracking branch 'origin/521-feat-add-moving-average-plot…
Gerhardsa0 d99898e
style: apply automated linter fixes
megalinter-bot ff91a74
fixed snapshots
Gerhardsa0 2590cee
style: apply automated linter fixes
megalinter-bot b5bad15
for some reason the numerical grouped snapshot fails
Gerhardsa0 abe17be
Merge remote-tracking branch 'origin/521-feat-add-moving-average-plot…
Gerhardsa0 2c76a38
style: apply automated linter fixes
megalinter-bot 9f4c7a9
Merge branch 'main' into 521-feat-add-moving-average-plot-1
Gerhardsa0 1d781cc
added GRU layer
Gerhardsa0 23ea410
Merge remote-tracking branch 'origin/521-feat-add-moving-average-plot…
Gerhardsa0 8dd5b87
fixed docs
Gerhardsa0 565ca55
added missing values for plot
Gerhardsa0 9133db9
linter changes and better error message
Gerhardsa0 f360168
style: apply automated linter fixes
megalinter-bot 3ffc640
linter changes and better error message
Gerhardsa0 c7002c5
Merge remote-tracking branch 'origin/521-feat-add-moving-average-plot…
Gerhardsa0 b88dfeb
removed grouped numerical
Gerhardsa0 8e6c178
style: apply automated linter fixes
megalinter-bot dcf27f3
changed one example
Gerhardsa0 b459805
Merge remote-tracking branch 'origin/521-feat-add-moving-average-plot…
Gerhardsa0 0d484f5
changed moving average plot, so it does not takes missing values
Gerhardsa0 2bd14bc
changed moving average plot, so it does not takes missing values
Gerhardsa0 7b31d53
Merge branch 'main' into 521-feat-add-moving-average-plot-1
Gerhardsa0 d557ce4
style: apply automated linter fixes
megalinter-bot 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
Large diffs are not rendered by default.
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
Binary file added
BIN
+23.2 KB
...apshots__/test_moving_average_plot/test_should_match_snapshot[date grouped].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
+22.2 KB
...ing/__snapshots__/test_moving_average_plot/test_should_match_snapshot[date].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.3 KB
..._snapshots__/test_moving_average_plot/test_should_match_snapshot[numerical].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 104 additions & 0 deletions
104
tests/safeds/data/tabular/plotting/test_moving_average_plot.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,104 @@ | ||
| import datetime | ||
|
|
||
| import pytest | ||
| from safeds.data.tabular.containers import Table | ||
| from safeds.exceptions import ColumnNotFoundError, ColumnTypeError | ||
| from syrupy import SnapshotAssertion | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("table", "x_name", "y_name", "window_size"), | ||
| [ | ||
| (Table({"A": [1, 2, 3], "B": [2, 4, 7]}), "A", "B", 2), | ||
| # (Table({"A": [1, 1, 2, 2, 3, 3, 4, 4, 5, 5], "B": [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]}), "A", "B", 2), | ||
| ( | ||
| Table( | ||
| { | ||
| "time": [ | ||
| datetime.date(2022, 1, 10), | ||
| datetime.date(2022, 1, 10), | ||
| datetime.date(2022, 1, 11), | ||
| datetime.date(2022, 1, 11), | ||
| datetime.date(2022, 1, 12), | ||
| datetime.date(2022, 1, 12), | ||
| ], | ||
| "A": [10, 5, 20, 2, 1, 1], | ||
| }, | ||
| ), | ||
| "time", | ||
| "A", | ||
| 2, | ||
| ), | ||
| ( | ||
| Table( | ||
| { | ||
| "time": [ | ||
| datetime.date(2022, 1, 9), | ||
| datetime.date(2022, 1, 10), | ||
| datetime.date(2022, 1, 11), | ||
| datetime.date(2022, 1, 12), | ||
| ], | ||
| "A": [10, 5, 20, 2], | ||
| }, | ||
| ), | ||
| "time", | ||
| "A", | ||
| 2, | ||
| ), | ||
| ], | ||
| ids=["numerical", "date grouped", "date"], | ||
sibre28 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| def test_should_match_snapshot( | ||
sibre28 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| table: Table, | ||
| x_name: str, | ||
| y_name: str, | ||
| window_size: int, | ||
| snapshot_png_image: SnapshotAssertion, | ||
| ) -> None: | ||
| line_plot = table.plot.moving_average_plot(x_name, y_name, window_size) | ||
| assert line_plot == snapshot_png_image | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("x", "y"), | ||
| [ | ||
| ("C", "A"), | ||
| ("A", "C"), | ||
| ("C", "D"), | ||
| ], | ||
| ids=["x column", "y column", "x and y column"], | ||
| ) | ||
| def test_should_raise_if_column_does_not_exist_error_message(x: str, y: str) -> None: | ||
| table = Table({"A": [1, 2, 3], "B": [2, 4, 7]}) | ||
| with pytest.raises(ColumnNotFoundError): | ||
| table.plot.moving_average_plot(x, y, window_size=2) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("table"), | ||
| [ | ||
| (Table({"A": [1, 2, 3], "B": ["2", 4, 7]})), | ||
| (Table({"A": ["1", 2, 3], "B": [2, 4, 7]})), | ||
| ], | ||
| ids=["x column", "y column"], | ||
| ) | ||
| def test_should_raise_if_column_is_not_numerical(table: Table) -> None: | ||
| with pytest.raises(ColumnTypeError): | ||
| table.plot.moving_average_plot("A", "B", window_size=2) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("table", "column_name"), | ||
| [ | ||
| (Table({"A": [1, 2, 3], "B": [None, 4, 7]}), "B"), | ||
| (Table({"A": [None, 2, 3], "B": [2, 4, 7]}), "A"), | ||
| ], | ||
| ids=["x column", "y column"], | ||
| ) | ||
| def test_should_raise_if_column_has_missing_value(table: Table, column_name: str) -> None: | ||
| with pytest.raises( | ||
| ValueError, | ||
| match=f"there are missing values in column '{column_name}', use transformation to fill missing " | ||
| f"values or drop the missing values", | ||
| ): | ||
| table.plot.moving_average_plot("A", "B", window_size=2) | ||
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.