Thanks to visit codestin.com
Credit goes to github.com

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
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Move input validation to below conversion to array
  • Loading branch information
samsontmr committed Jan 14, 2017
commit c353bce8981eff4db99421c7e3b2e2307b700207
21 changes: 10 additions & 11 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4758,12 +4758,6 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,

"""

for input in [('x', x), ('y1', y1), ('y2', y2)]:
if not (cbook.is_scalar(input[1]) or
cbook.is_scalar(cbook.safe_first_element(input[1]))):
raise ValueError('Input passed into argument "' + input[0] +
'" is not 1-dimensional.')

if not rcParams['_internal.classic_mode']:
color_aliases = mcoll._color_aliases
kwargs = cbook.normalize_kwargs(kwargs, color_aliases)
Expand All @@ -4781,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.

👍

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.

'" is not 1-dimensional.')

if y1.ndim == 0:
y1 = np.ones_like(x) * y1
if y2.ndim == 0:
Expand Down Expand Up @@ -4926,11 +4925,6 @@ def fill_betweenx(self, y, x1, x2=0, where=None,

"""

for input in [('y', y), ('x1', x1), ('x2', x2), ('where', where)]:
if not cbook.is_scalar(cbook.safe_first_element(input[1])):
raise ValueError('Input passed into argument "' + input[0] +
'" is not 1-dimensional.')

if not rcParams['_internal.classic_mode']:
color_aliases = mcoll._color_aliases
kwargs = cbook.normalize_kwargs(kwargs, color_aliases)
Expand All @@ -4947,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

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?

if array[1].ndim > 1:
raise ValueError('Input passed into argument "' + array[0] +
'" is not 1-dimensional.')

if x1.ndim == 0:
x1 = np.ones_like(y) * x1
if x2.ndim == 0:
Expand Down