Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 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
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
c055305
Add line tests for base module, changes to line methods in base module.
marty-larocque Mar 29, 2020
e0e3c34
Merge pull request #16 from earthlab/master
nkorinek Mar 30, 2020
60e57e4
Merge pull request #17 from earthlab/master
nkorinek Apr 6, 2020
2050f4b
Fixed bug with how line limits are checke
nkorinek Apr 13, 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
bfa569f
Minor change to assert_xy conversion method.
marty-larocque Apr 20, 2020
baee57e
Revert "Minor change to assert_xy conversion method."
marty-larocque Apr 20, 2020
bfc3321
merge
nkorinek Apr 20, 2020
44f0c3c
Merge branch 'master' into regression-asssert
Apr 23, 2020
66b8206
fix copyright on docs (#244)
Apr 21, 2020
63fa4e0
Add pillow (#254)
Apr 23, 2020
9ca93cf
Improved handline of lines without xy-data (Issue #238)
marty-larocque Apr 27, 2020
92ae521
Added docstrings to line tests.
marty-larocque Apr 27, 2020
5e33728
Added Seaborn to dev requirements
marty-larocque Apr 27, 2020
76f2624
Undo changes regarding x-limits problems (Issue #235)
marty-larocque Apr 27, 2020
c81f6d1
Merge branch 'master' into line_tests
marty-larocque Apr 27, 2020
d8e08c4
Merge branch 'master' into regression-asssert
Apr 27, 2020
d8b99e3
Fixed issue with new way of checking that the data is covered by the …
nkorinek Apr 27, 2020
5873fb6
Changelog update
nkorinek Apr 27, 2020
5756fa6
merge
nkorinek 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
75a8fb1
Merge branch 'master' into line_tests
marty-larocque May 4, 2020
5352acc
Made checking line coverage optional for base.assert_line()
marty-larocque May 4, 2020
5b51d0e
Fix double requirement in dev-requirements.txt
marty-larocque May 4, 2020
7dc3c9a
Change seaborn version
marty-larocque May 4, 2020
ae7c000
Seaborn requirement version change
marty-larocque May 4, 2020
cb9b6ad
update
nkorinek May 4, 2020
76648fd
Added comment to clarify changes
nkorinek May 4, 2020
7b887bd
merge
nkorinek May 7, 2020
1a2252a
Merge branch 'earthlab-master'
nkorinek May 7, 2020
ba3abfe
Merge branch 'master' of https://github.com/nkorinek/matplotcheck int…
nkorinek May 7, 2020
0a0e74b
Merging two similar PR's
nkorinek May 7, 2020
f37f009
Merged two PRs and made it so they pass pytest
nkorinek May 7, 2020
67749a1
black
nkorinek May 8, 2020
5901a56
Added more tests to test that the limit checks are correct in the ass…
nkorinek May 13, 2020
9c45947
pleasing flake8 issues that came up on the pr
nkorinek May 13, 2020
4c2329f
Merge branch 'master' into line_tests
May 14, 2020
a14718e
Update matplotcheck/base.py
May 14, 2020
fc4dfaf
Update matplotcheck/base.py
May 14, 2020
9a0b35f
small typo fix!
nkorinek May 14, 2020
f35181b
Merge branch 'line_tests' of https://github.com/nkorinek/matplotcheck…
nkorinek May 14, 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
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`
Unreleased
----------

- Changed how `assert_lines` checks the limits of lines (@nkorinek, #243)
- Changed changelog to an rst file. (@nkorinek, #266)
- Add a vignette for testing vector data plots. (@nkorinek, #208)
- Add ``pillow`` as a dev requirement (@lwasser, #253)
Expand All @@ -27,6 +28,9 @@ Unreleased
(@nkorinek, #121)
- Changed tolerance functionality from relative tolerance to absolute
tolerance. (@ryla5068, #234)
- Made checking line coverage optional for `base.assert_line()`
(@ryla5068, #239)
- Fixed bugs involving line tests (@ryla5068, #239)
- 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)

Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ setuptools==46.1.3
pre-commit==1.20.0
pip==19.0.3
descartes==1.1.0
seaborn>=0.9.1
pillow==7.1.2
161 changes: 100 additions & 61 deletions matplotcheck/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def _is_line(self):
"""

if self.ax.lines:
for l in self.ax.lines:
for line in self.ax.lines:
if (
not l.get_linestyle()
or not l.get_linewidth()
or l.get_linewidth() > 0
not line.get_linestyle()
or not line.get_linewidth()
or line.get_linewidth() > 0
):
return True

Expand All @@ -68,11 +68,11 @@ def _is_scatter(self):
if self.ax.collections:
return True
elif self.ax.lines:
for l in self.ax.lines:
for line in self.ax.lines:
if (
l.get_linestyle() == "None"
or l.get_linewidth() == "None"
or l.get_linewidth() == 0
line.get_linestyle() == "None"
or line.get_linewidth() == "None"
or line.get_linewidth() == 0
):
return True
return False
Expand Down Expand Up @@ -482,9 +482,9 @@ def assert_lims(
"""
# Get axis limit values
if axis == "x":
lims = [int(l) for l in self.ax.get_xlim()]
lims = [int(xlim) for xlim in self.ax.get_xlim()]
elif axis == "y":
lims = [int(l) for l in self.ax.get_ylim()]
lims = [int(ylim) for ylim in self.ax.get_ylim()]
else:
raise ValueError(
"axis must be one of the following string ['x', 'y']"
Expand Down Expand Up @@ -673,7 +673,7 @@ def assert_legend_labels(
legend_texts = [
t.get_text().lower() for leg in legends for t in leg.get_texts()
]
labels_exp = [l.lower() for l in labels_exp]
labels_exp = [label.lower() for label in labels_exp]

num_exp_labs = len(labels_exp)
num_actual_labs = len(legend_texts)
Expand Down Expand Up @@ -786,9 +786,12 @@ def get_xy(self, points_only=False):
if points_only:
xy_coords = [
val
for l in self.ax.lines
if (l.get_linestyle() == "None" or l.get_linewidth() == "None")
for val in l.get_xydata()
for line in self.ax.lines
if (
line.get_linestyle() == "None"
or line.get_linewidth() == "None"
)
for val in line.get_xydata()
] # .plot()
xy_coords += [
val
Expand All @@ -799,7 +802,7 @@ def get_xy(self, points_only=False):

else:
xy_coords = [
val for l in self.ax.lines for val in l.get_xydata()
val for line in self.ax.lines for val in line.get_xydata()
] # .plot()
xy_coords += [
val for c in self.ax.collections for val in c.get_offsets()
Expand Down Expand Up @@ -983,8 +986,8 @@ def assert_xlabel_ydata(
This is only testing the numbers in x-axis labels.
"""
x_data = [
"".join(c for c in l.get_text())
for l in self.ax.xaxis.get_majorticklabels()
"".join(c for c in label.get_text())
for label in self.ax.xaxis.get_majorticklabels()
]
y_data = self.get_xy()["y"]
xy_data = pd.DataFrame(data={"x": x_data, "y": y_data})
Expand Down Expand Up @@ -1068,62 +1071,89 @@ def assert_line(
self,
slope_exp,
intercept_exp,
xtime=False,
check_coverage=True,
message_no_line="Expected line not displayed",
message_data="Line does not cover data set",
):
"""Asserts that there exists a line on Axes `ax` with slope `slope_exp`
and y-intercept `intercept_exp` and goes at least from x coordinate
`min_val` to x coordinate `max_val`
and y-intercept `intercept_exp` and

Parameters
----------
slope_exp : float
Expected slope of line
intercept_exp : float
Expeted y intercept of line
xtime : boolean
Set ``True`` if x-axis values are datetime
check_coverage : boolean (default = True)
If `check_coverage` is `True`, function will check that the goes at
least from x coordinate `min_val` to x coordinate `max_val`. If the
line does not cover the entire dataset, and `AssertionError` with
be thrown with message `message_data`.
message_no_line : string
The error message to be displayed if the line does not exist.
message_data : string
The error message to be displayed if the line exists but does not
cover the dataset.
cover the dataset, and if `check_coverage` is `True`.

Raises
-------
AssertionError
with message `m` or `m2` if no line exists that covers the dataset
with message `message_no_line` or `message_data` if no line exists
that covers the dataset.
"""
flag_exist, flag_length = False, False
xy = self.get_xy(points_only=True)
min_val, max_val = min(xy["x"]), max(xy["x"])
flag_exist = False

if check_coverage:
flag_length = False
xy = self.get_xy(points_only=True)
min_val, max_val = min(xy["x"]), max(xy["x"])

for line in self.ax.lines:
# Here we will get the verticies for the line and reformat them in

# the way that get_slope_yintercept() expects
data = line.get_data()
path_verts = np.column_stack((data[0], data[1]))

for l in self.ax.lines:
path_verts = self.ax.transData.inverted().transform(
l._transformed_path.get_fully_transformed_path().vertices
)
slope, y_intercept = self.get_slope_yintercept(path_verts)
if math.isclose(slope, slope_exp, abs_tol=1e-4) and math.isclose(
y_intercept, intercept_exp, abs_tol=1e-4
):
flag_exist = True
line_x_vals = [coord[0] for coord in path_verts]
if min(line_x_vals) <= min_val and max(line_x_vals) >= max_val:
flag_length = True
break

# This check ensures that the minimum and maximum values of the
# line are within or very close to the minimum and maximum
# values in the pandas dataframe provided. This accounts for
# small errors sometimes found in matplotlib plots.
if check_coverage:
if (
math.isclose(min(line_x_vals), min_val, abs_tol=1e-4)
or min(line_x_vals) <= min_val
) and (
math.isclose(max(line_x_vals), max_val, abs_tol=1e-4)
or max(line_x_vals) >= max_val
):
flag_length = True
break

assert flag_exist, message_no_line
assert flag_length, message_data
if check_coverage:
assert flag_length, message_data

def assert_lines_of_type(self, line_types):
def assert_lines_of_type(self, line_types, check_coverage=True):
"""Asserts each line of type in `line_types` exist on `ax`

Parameters
----------
line_types : list of strings
line_types : string or list of strings
Acceptable strings in line_types are as follows
``['regression', 'onetoone']``.
``['linear-regression', 'onetoone']``.
check_coverage : boolean (default = True)
If `check_coverage` is `True`, function will check that the goes at
least from x coordinate `min_val` to x coordinate `max_val`. If the
line does not cover the entire dataset, and `AssertionError` with
be thrown with message `message_data`.

Raises
-------
Expand All @@ -1134,31 +1164,40 @@ def assert_lines_of_type(self, line_types):
-----
If `line_types` is empty, assertion is passed.
"""
if line_types:
for line_type in line_types:
if line_type == "regression":
xy = self.get_xy(points_only=True)
slope_exp, intercept_exp, _, _, _ = stats.linregress(
xy.x, xy.y
if isinstance(line_types, str):
line_types = [line_types]

for line_type in line_types:
if line_type == "linear-regression":
xy = self.get_xy(points_only=True)
# Check that there is xy data for this line. Some one-to-one
# lines do not produce xy data.
if xy.empty:
raise AssertionError(
"linear-regression line not displayed properly"
)
elif line_type == "onetoone":
slope_exp, intercept_exp = 1, 0
else:
raise ValueError(
"each string in line_types must be from the following "
+ '["regression","onetoone"]'
)

self.assert_line(
slope_exp,
intercept_exp,
message_no_line="{0} line not displayed properly".format(
line_type
),
message_data="{0} line does not cover dataset".format(
line_type
),
slope_exp, intercept_exp, _, _, _ = stats.linregress(
xy.x, xy.y
)
elif line_type == "onetoone":
slope_exp, intercept_exp = 1, 0
else:
raise ValueError(
"each string in line_types must be from the following "
+ '["linear-regression","onetoone"]'
)

self.assert_line(
slope_exp,
intercept_exp,
message_no_line="{0} line not displayed properly".format(
line_type
),
message_data="{0} line does not cover dataset".format(
line_type
),
check_coverage=check_coverage,
)

# HISTOGRAM FUNCTIONS

Expand Down
Loading