[go: up one dir, main page]

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

ENH: add disjoint_subset_union and disjoint_subset_union_all #1982

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

Conversation

martinfleis
Copy link
Contributor

Exposing GEOSDisjointSubsetUnion as disjoint_subset_union and disjoint_subset_union_all, matching the API of union and coverage_union (assuming coverage_unoin will be fixed as discussed in #1963).

Tests are currently only reusing the tooling for other set operations. Not sure if there's a need to go beyond that.

xref #1510

Comment on lines 544 to 551
if isinstance(a, Geometry | None) and isinstance(b, Geometry | None):
pass
elif isinstance(a, Geometry | None):
a = np.full_like(b, a)
elif isinstance(b, Geometry | None):
b = np.full_like(a, b)
elif len(a) != len(b):
raise ValueError("Arrays a and b must have the same length")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since disjoint_subset_union operates on a GeometryCollection, we need to roll-out custom broadcasting here.

@coveralls
Copy link
coveralls commented Feb 6, 2024

Pull Request Test Coverage Report for Build 7878233005

Details

  • -3 of 23 (86.96%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall first build on disjoint_subset_union at 88.059%

Changes Missing Coverage Covered Lines Changed/Added Lines %
shapely/set_operations.py 20 23 86.96%
Totals Coverage Status
Change from base Build 7874085015: 88.1%
Covered Lines: 2618
Relevant Lines: 2973

💛 - Coveralls

Copy link
Member
@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Thanks a lot, looks good! A few minor comments

src/ufuncs.c Outdated Show resolved Hide resolved
shapely/set_operations.py Show resolved Hide resolved
shapely/set_operations.py Outdated Show resolved Hide resolved
shapely/tests/test_set_operations.py Outdated Show resolved Hide resolved
Comment on lines +545 to +554
if (isinstance(a, Geometry) or a is None) and (
isinstance(b, Geometry) or b is None
):
pass
elif isinstance(a, Geometry) or a is None:
a = np.full_like(b, a)
elif isinstance(b, Geometry) or b is None:
b = np.full_like(a, b)
elif len(a) != len(b):
raise ValueError("Arrays a and b must have the same length")
Copy link
Member

Choose a reason for hiding this comment

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

The logic looks good here (to mimic broadcasting), just wondering if this is already covered by the standard tests we have? (did you have to add this to get the tests passing?)

Copy link
Member

Choose a reason for hiding this comment

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

Ah, and it might be that this can be simplified as a, b = np.broadcast_arrays(a, b)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried broadcast_array before writing this and it does not work as we need it. Some of the tests fail with TypeError: One of the arguments is of incorrect type. Please provide only Geometry objects.

And yes, I had to include this to make the tests green, so it is properly covering by existing tests.

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