Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
8344d56
Merge pull request #1 from earthlab/master
nkorinek Feb 6, 2020
b87394d
Merge pull request #2 from earthlab/master
nkorinek Feb 12, 2020
7cf2703
Merge pull request #3 from earthlab/master
nkorinek Feb 12, 2020
c4d904e
Merge pull request #4 from earthlab/master
nkorinek Feb 13, 2020
c6deb54
Merge pull request #5 from earthlab/master
nkorinek Feb 13, 2020
30b4aa1
Merge pull request #7 from earthlab/master
nkorinek Feb 17, 2020
6ab2486
Merge pull request #8 from earthlab/master
nkorinek Mar 3, 2020
5077e25
Merge pull request #9 from earthlab/master
nkorinek Mar 7, 2020
4ff1b26
Merge pull request #10 from earthlab/master
nkorinek Mar 11, 2020
6f54aea
Added tests for timeseries module.
marty-larocque Mar 16, 2020
de25545
Merge pull request #11 from earthlab/master
nkorinek Mar 19, 2020
2f2f01d
Merge pull request #12 from earthlab/master
nkorinek Mar 19, 2020
031a710
Merge pull request #13 from earthlab/master
nkorinek Mar 20, 2020
7bb3216
Merge pull request #14 from earthlab/master
nkorinek Mar 23, 2020
cd169d3
Merge pull request #15 from earthlab/master
nkorinek Mar 24, 2020
bfafa8a
Fixed a bug where assert_xydata() sometimes failed to compare numpy a…
marty-larocque Mar 26, 2020
5a53ad4
Changed behavior of assert_xydata() to display standard error message…
marty-larocque Mar 26, 2020
71d43f7
Merge branch 'master' into timeseries_tests_2
marty-larocque Mar 27, 2020
e0e3c34
Merge pull request #16 from earthlab/master
nkorinek Mar 30, 2020
39ba373
remove extensive docs within test file
Apr 6, 2020
60e57e4
Merge pull request #17 from earthlab/master
nkorinek Apr 6, 2020
5569d18
Merge pull request #18 from earthlab/master
nkorinek Apr 20, 2020
90b8128
Update setuptools from 42.0.2 to 45.2.0 (#190)
pyup-bot Feb 11, 2020
c96321c
raster inherits from vector rather than base (#76)
Feb 12, 2020
8e26cba
Allow geodataframes in assert_polygons (#188)
nkorinek Feb 13, 2020
49c4c24
fixing a few syntax errors (#194)
Feb 13, 2020
da32ef9
update changelog for release
Feb 14, 2020
f842822
Bump version: 0.1.1 → 0.1.2
Feb 14, 2020
eee471f
Add flake8 fix [WIP] (#199)
nkorinek Mar 2, 2020
77e8f76
Assert string accept spaces (#205)
nkorinek Mar 6, 2020
99e961a
Update codecov to 2.0.16 (#202)
pyup-bot Mar 7, 2020
3c37b7d
Contributors update (#213)
nkorinek Mar 10, 2020
d2dfa5a
Update setuptools from 45.2.0 to 46.0.0 (#215)
pyup-bot Mar 10, 2020
6b142e8
Add Assert points function & cleanup duplicate methods (#203)
nkorinek Mar 19, 2020
7ea9490
Update pytest from 5.3.5 to 5.4.1
pyup-bot Mar 13, 2020
a782271
merge
nkorinek Apr 20, 2020
e7b4652
Additional vector tests (#212)
nkorinek Mar 23, 2020
0f2fc16
Add tests to the Autograde module (#224)
nkorinek Mar 24, 2020
27251c3
Hist bin midpoints (#204)
nkorinek Mar 26, 2020
f3c384f
Update setuptools from 46.1.1 to 46.1.3 (#231)
pyup-bot Mar 26, 2020
654b3d1
Title assert accepts strings (#229)
nkorinek Apr 2, 2020
34e20da
M2r remove (#247)
nkorinek Apr 20, 2020
eb4c2d8
merge
nkorinek Apr 20, 2020
3f07d9b
# This is a combination of 2 commits.
pyup-bot Feb 11, 2020
beae1b5
Updating in order to squash commits!
nkorinek Apr 20, 2020
1868034
Change handling of arrays of different shape from AssertionError to V…
marty-larocque Apr 23, 2020
152a291
Merge branch 'timeseries_tests_2' of https://github.com/ryla5068/matp…
marty-larocque Apr 23, 2020
5046a68
Updated Changelog
marty-larocque Apr 23, 2020
66b8206
fix copyright on docs (#244)
Apr 21, 2020
63fa4e0
Add pillow (#254)
Apr 23, 2020
f33993f
Update matplotcheck/base.py
Apr 24, 2020
8035977
PEP 8 import order
Apr 27, 2020
3adf713
pep 8 imports fix
Apr 27, 2020
f52150a
Merge
nkorinek Apr 27, 2020
5f0fd98
Merge branch 'earthlab-master'
nkorinek Apr 27, 2020
efab5a2
Changelog to rst (#267)
nkorinek May 1, 2020
a7dfdc7
setup greetings! (#257)
May 1, 2020
473098a
Final changes
marty-larocque May 4, 2020
8ef9703
Merge branch 'master' into timeseries_tests_2
marty-larocque May 4, 2020
c3990da
delete markdown changelog
May 7, 2020
1949eeb
Added changes to take away unneccesary parameters
nkorinek May 7, 2020
7b887bd
merge
nkorinek May 7, 2020
1a2252a
Merge branch 'earthlab-master'
nkorinek May 7, 2020
176e613
merge with masster
nkorinek May 7, 2020
16af26b
fixed merge error
nkorinek May 7, 2020
8059586
black
nkorinek May 7, 2020
cc2d740
small reword to force rebuild
nkorinek May 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Unreleased
(@nkorinek, #121)
- Changed tolerance functionality from relative tolerance to absolute
tolerance. (@ryla5068, #234)
- Improved handling of datasets with different shapes in base.assert_xy() (@ryla5068, #233)
- Bug fix for handling object datatypes in base.assert_xy() (@ryla5068, #232)

0.1.2
-----
Expand Down
54 changes: 30 additions & 24 deletions matplotcheck/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
"""

import numpy as np
import matplotlib.dates as mdates
import matplotlib
from matplotlib.backend_bases import RendererBase
import math
from scipy import stats
import pandas as pd
import geopandas as gpd
import numbers
import geopandas as gpd


class InvalidPlotError(Exception):
Expand Down Expand Up @@ -766,7 +765,7 @@ def assert_no_legend_overlap(self, message="Legends overlap eachother"):

""" BASIC PLOT DATA FUNCTIONS """

def get_xy(self, points_only=False, xtime=False):
def get_xy(self, points_only=False):
"""Returns a pandas dataframe with columns "x" and "y" holding the x
and y coords on Axes `ax`

Expand All @@ -777,9 +776,6 @@ def get_xy(self, points_only=False, xtime=False):
points_only : boolean
Set ``True`` to check only points, set ``False`` to check all data
on plot.
xtime : boolean
Set equal to True if the x axis of the plot contains datetime
values

Returns
-------
Expand Down Expand Up @@ -820,9 +816,6 @@ def get_xy(self, points_only=False, xtime=False):
xy_data = xy_data[xy_data["x"] >= lims[0]]
xy_data = xy_data[xy_data["x"] <= lims[1]].reset_index(drop=True)

# change to datetime dtype if needed
if xtime:
xy_data["x"] = mdates.num2date(xy_data["x"])
return xy_data

def assert_xydata(
Expand All @@ -831,7 +824,6 @@ def assert_xydata(
xcol=None,
ycol=None,
points_only=False,
xtime=False,
xlabels=False,
tolerance=0,
message="Incorrect data values",
Expand All @@ -856,11 +848,6 @@ def assert_xydata(
points_only : boolean,
Set ``True`` to check only points, set ``False`` tp check all data
on plot.
xtime : boolean
Set ``True`` if the a-axis contains datetime values. Matplotlib
converts datetime objects to seconds? This parameter will ensure
the provided x col values are converted if they are datetime
elements.
xlabels : boolean
Set ``True`` if using x axis labels rather than x data. Instead of
comparing numbers in the x-column to expected, compares numbers or
Expand Down Expand Up @@ -906,7 +893,7 @@ def assert_xydata(
xy_expected, xcol=xcol, ycol=ycol, message=message
)
return
xy_data = self.get_xy(points_only=points_only, xtime=xtime)
xy_data = self.get_xy(points_only=points_only)

# Make sure the data are sorted the same
xy_data, xy_expected = (
Expand All @@ -915,8 +902,6 @@ def assert_xydata(
)

if tolerance > 0:
if xtime:
raise ValueError("tolerance must be 0 with datetime on x-axis")
np.testing.assert_allclose(
xy_data["x"],
xy_expected[xcol],
Expand All @@ -934,20 +919,41 @@ def assert_xydata(
"""We use `assert_array_max_ulp()` to compare the
two datasets because it is able to account for small errors in
floating point numbers, and it scales nicely between extremely
small or large numbers. We catch this error and throw our own so
that we can use our own message."""
small or large numbers. Because of the way that matplotlib stores
datetime data, this is essential for comparing high-precision
datetime data (i.e. millisecond or lower).

We catch this error and raise our own that is more relevant to
the assertion being run."""
try:
np.testing.assert_array_max_ulp(
np.array(xy_data["x"]), np.array(xy_expected[xcol])
xy_data["x"].to_numpy(dtype=np.float64),
xy_expected[xcol].to_numpy(dtype=np.float64),
5,
)
except AssertionError:
# xy_data and xy_expected do not contain the same data
raise AssertionError(message)
except ValueError:
# xy_data and xy_expected do not have the same shape
raise ValueError(
"xy_data and xy_expected do not have the same shape"
)
try:
np.testing.assert_array_max_ulp(
np.array(xy_data["y"]), np.array(xy_expected[ycol])
xy_data["y"].to_numpy(dtype=np.float64),
xy_expected[ycol].to_numpy(dtype=np.float64),
5,
)

except AssertionError:
# xy_data and xy_expected do not contain the same data
raise AssertionError(message)
except ValueError:
# xy_data and xy_expected do not have the same shape
raise ValueError(
"xy_data and xy_expected do not have the same shape"
)

def assert_xlabel_ydata(
self, xy_expected, xcol, ycol, message="Incorrect Data"
Expand Down Expand Up @@ -1015,7 +1021,7 @@ def assert_xlabel_ydata(
if x_is_numeric:
try:
np.testing.assert_array_max_ulp(
np.array(xy_data["x"]), np.array(xy_expected[xcol])
np.array(xy_data["x"]), np.array(xy_expected[xcol]),
)
except AssertionError:
raise AssertionError(message)
Expand Down Expand Up @@ -1167,7 +1173,7 @@ def get_num_bins(self):
overlapping or stacked histograms in the same
`matplotlib.axis.Axis` object, then this returns the number of bins
with unique edges. """
x_data = self.get_xy(xtime=False)["x"]
x_data = self.get_xy()["x"]
unique_x_data = list(set(x_data))
num_bins = len(unique_x_data)

Expand Down
82 changes: 74 additions & 8 deletions matplotcheck/tests/test_timeseries_module.py
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


@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")