Skip to content

points_in_path can fail with NaN data #3759

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 2 commits into from
Nov 7, 2014

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Nov 5, 2014

from matplotlib.path import Path
import numpy as np
box = np.array([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]])
p = Path(box)
test = np.array([[np.nan, 0.5]])
p.contains_points(test)  # array([ True], dtype=bool)

@mdboom
Copy link
Member

mdboom commented Nov 5, 2014

Good point. It should be an easy enough fix.

@mdboom mdboom self-assigned this Nov 5, 2014
@mdboom
Copy link
Member

mdboom commented Nov 5, 2014

Fix attached. This may require some non-straightforward merging to master, but I'll deal with that once this is merged.

box = np.array([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]])
p = Path(box)
test = np.array([[np.nan, 0.5]])
assert p.contains_points(test)[0] == False
Copy link
Member

Choose a reason for hiding this comment

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

I would also add a test on the length.

Copy link
Member

Choose a reason for hiding this comment

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

and pep8 seems to want this to be assert not p.contaions_point(test)[0]

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool. I've fixed both.

@jenshnielsen
Copy link
Member

Looks good

jenshnielsen added a commit that referenced this pull request Nov 7, 2014
points_in_path can fail with NaN data
@jenshnielsen jenshnielsen merged commit 58a3280 into matplotlib:v1.4.x Nov 7, 2014
p = Path(box)
test = np.array([[np.nan, 0.5]])
contains = p.contains_points(test)
assert len(contains) == 1
Copy link
Member

Choose a reason for hiding this comment

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

why isn't the length 2?

Copy link
Member

Choose a reason for hiding this comment

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

Because "test" is length 1

On Fri, Nov 7, 2014 at 9:05 AM, Thomas A Caswell notifications@github.com
wrote:

In lib/matplotlib/tests/test_path.py:

@@ -61,6 +61,15 @@ def test_path_clipping():
xy, facecolor='none', edgecolor='red', closed=True))

+def test_point_in_path_nan():

  • box = np.array([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]])
  • p = Path(box)
  • test = np.array([[np.nan, 0.5]])
  • contains = p.contains_points(test)
  • assert len(contains) == 1

why isn't the length 2?


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/3759/files#r20011300.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah -- a single point (which is an x, y pair) is being tested.

Copy link
Member

Choose a reason for hiding this comment

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

Right, sorry for the brains-bar comment.

On Fri Nov 07 2014 at 11:23:55 AM Michael Droettboom <
notifications@github.com> wrote:

In lib/matplotlib/tests/test_path.py:

@@ -61,6 +61,15 @@ def test_path_clipping():
xy, facecolor='none', edgecolor='red', closed=True))

+def test_point_in_path_nan():

  • box = np.array([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]])
  • p = Path(box)
  • test = np.array([[np.nan, 0.5]])
  • contains = p.contains_points(test)
  • assert len(contains) == 1

Yeah -- a single point (which is an x, y pair) is being tested.


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/3759/files#r20019732.

tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Nov 11, 2014
Conflicts:
	src/_path.cpp

src/_path.cpp has been deleted on master, need to apply
the changes to fix matplotlib#3759 to src/_path.h
@mdboom mdboom deleted the point_in_path_nan branch March 3, 2015 18:44
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.

4 participants