-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
better input validation on fill_between
#7817
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
Conversation
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.
Overall, it looks good, except for the failing tests.
I am not a big fan of the name input
in the code, but haven't come up with something better (yet).
Once the tests are fixed, I think this can be merged.
@@ -725,6 +725,42 @@ def test_polycollection_joinstyle(): | |||
ax.set_ybound(0, 3) | |||
|
|||
|
|||
@raises(ValueError) |
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.
I have no clue why this doesn't fail for all the builds.
Raises is not defined. I think you need to use the "new" pytest way of doing this:
def test_fill between_2d_x_input():
…
with pytest.raises(ValueError):
ax.plot(…)
I would put the check much lower, after conversion to arrays ( |
@@ -4774,6 +4775,11 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False, | |||
y1 = ma.masked_invalid(self.convert_yunits(y1)) | |||
y2 = ma.masked_invalid(self.convert_yunits(y2)) | |||
|
|||
for array in [('x', x), ('y1', y1), ('y2', y2)]: |
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.
for name, array in ...
@@ -4774,6 +4775,11 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False, | |||
y1 = ma.masked_invalid(self.convert_yunits(y1)) | |||
y2 = ma.masked_invalid(self.convert_yunits(y2)) | |||
|
|||
for name, array in [('x', x), ('y1', y1), ('y2', y2)]: | |||
if array.ndim > 1: | |||
raise ValueError('Input passed into argument "' + name + |
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.
"Input passed into argument {!r}".format(name)
(or "... %r" % name
if you're really old-styled).
Same fixes need to be applied below.
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.
There is still a minor mistake that makes the tests fail.
Once this is fixed, it's good to go for me!
@@ -4774,6 +4775,11 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False, | |||
y1 = ma.masked_invalid(self.convert_yunits(y1)) | |||
y2 = ma.masked_invalid(self.convert_yunits(y2)) | |||
|
|||
for name, array in [('x', x), ('y1', y1), ('y2', y2)]: |
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.
👍
@@ -4934,6 +4941,11 @@ def fill_betweenx(self, y, x1, x2=0, where=None, | |||
x1 = ma.masked_invalid(self.convert_xunits(x1)) | |||
x2 = ma.masked_invalid(self.convert_xunits(x2)) | |||
|
|||
for array in [('x', x), ('y1', y1), ('y2', y2)]: |
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.
I think there is a slight mistake here: the arguments are "y", "x1" and "x2".
The documentation and examples don't run.
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.
Good catch, thanks! Will change it now
@@ -4934,6 +4941,11 @@ def fill_betweenx(self, y, x1, x2=0, where=None, | |||
x1 = ma.masked_invalid(self.convert_xunits(x1)) | |||
x2 = ma.masked_invalid(self.convert_xunits(x2)) | |||
|
|||
for array in [('x', x), ('y1', y1), ('y2', y2)]: |
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.
Any reason not to use name, array
as above?
Added @cleanup at the top of the tests. I suspect that was what caused some of the build jobs to fail |
Current coverage is 62.10% (diff: 66.66%)@@ master #7817 diff @@
==========================================
Files 174 174
Lines 56051 56057 +6
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 34810 34815 +5
- Misses 21241 21242 +1
Partials 0 0
|
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.
I think all of @NelleV 's concerns have been addressed.
fill_between
fill_between
Thanks! |
fill_between
fill_between
Fixes #7510