-
Notifications
You must be signed in to change notification settings - Fork 11
Adding tests for timeseries module #219
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
Closed
marty-larocque
wants to merge
14
commits into
earthlab:master
from
marty-larocque:timeseries_tests_2
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6f54aea
Added tests for timeseries module.
marty-larocque bfafa8a
Fixed a bug where assert_xydata() sometimes failed to compare numpy a…
marty-larocque 5a53ad4
Changed behavior of assert_xydata() to display standard error message…
marty-larocque 71d43f7
Merge branch 'master' into timeseries_tests_2
marty-larocque 39ba373
remove extensive docs within test file
1868034
Change handling of arrays of different shape from AssertionError to V…
marty-larocque 152a291
Merge branch 'timeseries_tests_2' of https://github.com/ryla5068/matp…
marty-larocque 5046a68
Updated Changelog
marty-larocque f33993f
Update matplotcheck/base.py
8035977
PEP 8 import order
3adf713
pep 8 imports fix
473098a
Final changes
marty-larocque 8ef9703
Merge branch 'master' into timeseries_tests_2
marty-larocque c3990da
delete markdown changelog
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
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
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 |
|---|---|---|
| @@ -1,9 +1,75 @@ | ||
| ''' | ||
| def test_assert_xydata_timeseries(pt_time_line_plt, pd_df_timeseries): | ||
| """Commenting this out for now as this requires a time series data object | ||
| this is failing because the time data needs to be in seconds like how | ||
| mpl saves it. """ | ||
| pt_time_line_plt.assert_xydata( | ||
| pd_df_timeseries, xcol='time', ycol='A', xtime=True | ||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
| import pandas as pd | ||
| import pytest | ||
| from matplotcheck.timeseries import TimeSeriesTester | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These import should be in pep8 order, matplotcheck being imported last |
||
|
|
||
| @pytest.fixture | ||
| def pd_df_timeseries(): | ||
| """Create a pandas dataframe for testing, with timeseries in one column""" | ||
| return pd.DataFrame( | ||
| { | ||
| "time": pd.date_range(start="1/1/2018", periods=100), | ||
| "A": np.random.randint(0, 100, size=100), | ||
| } | ||
| ) | ||
| ''' | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def pt_time_line_plt(pd_df_timeseries): | ||
| """Create timeseries line plot for testing""" | ||
| fig, ax = plt.subplots() | ||
| pd_df_timeseries.plot("time", "A", kind="line", ax=ax) | ||
| axis = plt.gca() | ||
|
|
||
| return TimeSeriesTester(axis) | ||
|
|
||
|
|
||
| def test_assert_xydata_timeseries(pt_time_line_plt): | ||
| """Tests that assert_xydata() correctly passes with matching timeseries | ||
| data.""" | ||
| data = pt_time_line_plt.get_xy() | ||
| pt_time_line_plt.assert_xydata(data, xcol="x", ycol="y") | ||
|
|
||
|
|
||
| def test_assert_xydata_timeseries_fails(pt_time_line_plt): | ||
| """Tests that assert_xydata() correctly fails without matching timeseries | ||
| data.""" | ||
| data = pt_time_line_plt.get_xy() | ||
| data.loc[0, "x"] = 100 | ||
| with pytest.raises(AssertionError, match="Incorrect data values"): | ||
| pt_time_line_plt.assert_xydata(data, xcol="x", ycol="y") | ||
|
|
||
|
|
||
| def test_assert_xydata_timeseries_truncation_error( | ||
| pt_time_line_plt, pd_df_timeseries | ||
| ): | ||
| """Tests that assert_xydata() handles floating-point truncation error | ||
| gracefully for timeseries data.""" | ||
|
|
||
| pt1 = pt_time_line_plt | ||
|
|
||
| # Create second plottester object with slightly different time values | ||
| # The change in values here should be small enough that it gets truncated | ||
| # in matplotlib's conversion of datetime data | ||
| for i in range(len(pd_df_timeseries)): | ||
| pd_df_timeseries.loc[i, "time"] = pd_df_timeseries.loc[ | ||
| i, "time" | ||
| ] + pd.Timedelta(1) | ||
| fig, ax2 = plt.subplots() | ||
| pd_df_timeseries.plot("time", "A", kind="line", ax=ax2) | ||
| pt2 = TimeSeriesTester(ax2) | ||
|
|
||
| # Test that the two datasets assert as equal | ||
| data1 = pt1.get_xy() | ||
| pt2.assert_xydata(data1, xcol="x", ycol="y") | ||
|
|
||
|
|
||
| def test_assert_xydata_timeseries_roundoff_error(pt_time_line_plt): | ||
| """Tests that assert_xydata() handles floating-point roundoff error | ||
| gracefully for timeseries data.""" | ||
| data = pt_time_line_plt.get_xy() | ||
| data.loc[0, "x"] = data.loc[0, "x"] + 0.00000000001 | ||
|
|
||
| pt_time_line_plt.assert_xydata(data, xcol="x", ycol="y") | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious what the 5 is here that was added? @nkorinek when you look at this PR can you please see if it makes sense to you to have 5 there?