Skip to content
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

PERF: improve MultiPoint(..) constructor from numpy array of coordinate values #1961

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jorisvandenbossche
Copy link
Member

Addresses #1954

@coveralls
Copy link

Pull Request Test Coverage Report for Build 7401687526

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.3%) to 88.01%

Totals Coverage Status
Change from base Build 7178707979: 0.3%
Covered Lines: 2591
Relevant Lines: 2944

💛 - Coveralls

@jobh
Copy link

jobh commented Jan 4, 2024

Looks good!

Just a heads-up, there is a semantic change because an all-NaN point is considered an empty geometry:

coords = np.array([[np.nan, np.nan]])
shapely.MultiPoint(coords)  # before PR
# EmptyPartError: Can't create MultiPoint with empty component
shapely.MultiPoint(coords)  # after PR
# <MULTIPOINT EMPTY>

@jorisvandenbossche
Copy link
Member Author

Good point! We should try to keep that consistent. The points() constructor now has a handle_nan keyword that can be set to disallow NaNs.

Now, that would also disallow single NaNs for just x or y, which currently is allowed:

In [7]: shapely.MultiPoint([(0, 1), (2, np.nan)])
Out[7]: <MULTIPOINT ((0 1), (2 NaN))>

so if we want to retain the actual current behaviour of MultiPoint(..), we could also first create points, and then just use the vectorized method to check if there are any empties in there.

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.

None yet

3 participants