Skip to content

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

Merged
merged 4 commits into from
Jan 18, 2017
Merged

Conversation

samsontmr
Copy link
Contributor

Fixes #7510

Copy link
Member

@NelleV NelleV left a 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)
Copy link
Member

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(…)

@anntzer
Copy link
Contributor

anntzer commented Jan 14, 2017

I would put the check much lower, after conversion to arrays (x = ma.masked_invalid(self.convert_xunits(x)) and so on). Then you can just check for x.ndim and so on.

@@ -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)]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for name, array in ...

@samsontmr
Copy link
Contributor Author

Done! @anntzer @NelleV

@@ -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 +
Copy link
Contributor

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.

Copy link
Member

@NelleV NelleV left a 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)]:
Copy link
Member

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)]:
Copy link
Member

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.

Copy link
Contributor Author

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)]:
Copy link
Member

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?

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Jan 15, 2017
@samsontmr
Copy link
Contributor Author

samsontmr commented Jan 16, 2017

Added @cleanup at the top of the tests. I suspect that was what caused some of the build jobs to fail

@codecov-io
Copy link

Current coverage is 62.10% (diff: 66.66%)

Merging #7817 into master will increase coverage by <.01%

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

Powered by Codecov. Last update b6709ea...e702cd8

Copy link
Member

@tacaswell tacaswell left a 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.

@tacaswell tacaswell changed the title better input validation on fill_between [MRG+1] better input validation on fill_between Jan 16, 2017
@anntzer anntzer merged commit 19a830e into matplotlib:master Jan 18, 2017
@anntzer
Copy link
Contributor

anntzer commented Jan 18, 2017

Thanks!

@anntzer anntzer changed the title [MRG+1] better input validation on fill_between better input validation on fill_between Jan 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants