Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Improve barbs() error message#7407
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -392,6 +392,12 @@ def _parse_args(*args): | ||
return X, Y, U, V, C | ||
def _check_consistent_shapes(*arrays): | ||
all_shapes = set(a.shape for a in arrays) | ||
if len(all_shapes) != 1: | ||
raise ValueError('The shapes of the passed in arrays do not match.') | ||
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. 👍 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. I think that line is too long (pep8 is complaining somewhere). 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. Nope, even worse--it was the docstring typo I fixed. I rewrapped and pushed. | ||
class Quiver(mcollections.PolyCollection): | ||
""" | ||
Specialized PolyCollection for arrows. | ||
@@ -1124,9 +1130,11 @@ def set_UVC(self, U, V, C=None): | ||
x, y, u, v, c = delete_masked_points(self.x.ravel(), | ||
self.y.ravel(), | ||
self.u, self.v, c) | ||
_check_consistent_shapes(x, y, u, v, c) | ||
else: | ||
x, y, u, v = delete_masked_points(self.x.ravel(), self.y.ravel(), | ||
self.u, self.v) | ||
_check_consistent_shapes(x, y, u, v) | ||
magnitude = np.hypot(u, v) | ||
flags, barbs, halves, empty = self._find_tails(magnitude, | ||
@@ -1151,16 +1159,17 @@ def set_UVC(self, U, V, C=None): | ||
def set_offsets(self, xy): | ||
""" | ||
Set the offsets for the barb polygons. This saves theoffsets passed | ||
inand actually sets version masked as appropriate for the existing | ||
U/Vdata. *offsets* should be a sequence. | ||
ACCEPTS: sequence of pairs of floats | ||
""" | ||
self.x = xy[:, 0] | ||
self.y = xy[:, 1] | ||
x, y, u, v = delete_masked_points(self.x.ravel(), self.y.ravel(), | ||
self.u, self.v) | ||
_check_consistent_shapes(x, y, u, v) | ||
xy = np.hstack((x[:, np.newaxis], y[:, np.newaxis])) | ||
mcollections.PolyCollection.set_offsets(self, xy) | ||
self.stale = True | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from __future__ import print_function | ||
import warnings | ||
import numpy as np | ||
from nose.tools import raises | ||
import sys | ||
from matplotlib import pyplot as plt | ||
from matplotlib.testing.decorators import cleanup | ||
@@ -133,6 +134,20 @@ def test_barbs(): | ||
cmap='viridis') | ||
@cleanup | ||
@raises(ValueError) | ||
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. Just a thought: we could avoid falling back to @cleanupdeftest_bad_masked_sizes():'Test error handling when given differing sized masked arrays'x=np.arange(3)y=np.arange(3)u=np.ma.array(15.*np.ones((4,)))v=np.ma.array(15.*np.ones_like(u))u[1]=np.ma.maskedv[1]=np.ma.maskedfig,ax=plt.subplots()withpytest.raises(ValueError):ax.barbs(x,y,u,v) 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. If we're allowed to explicitly use pytest now, I will absolutely do that. I just tried to be consistent with what's already around. 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. I'm not seeing anywhere that we're explicitly using pytest yet...I sense this shouldn't be the first. 😞 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. oh, I thought it was official! 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. I personally don't care… I much prefer nose's API than pytests, so I have a tendency to use naturally pytest. I'd be interested in knowing whether we should write everything pytest-like. 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. Ah...on master. 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. Oops. Sorry for the noise. I missed the destination for this. | ||
def test_bad_masked_sizes(): | ||
'Test error handling when given differing sized masked arrays' | ||
x = np.arange(3) | ||
y = np.arange(3) | ||
u = np.ma.array(15. * np.ones((4,))) | ||
v = np.ma.array(15. * np.ones_like(u)) | ||
u[1] = np.ma.masked | ||
v[1] = np.ma.masked | ||
fig, ax = plt.subplots() | ||
ax.barbs(x, y, u, v) | ||
if __name__ == '__main__': | ||
import nose | ||
nose.runmodule() |