-
Notifications
You must be signed in to change notification settings - Fork 565
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
base: main
Are you sure you want to change the base?
Conversation
shapely/set_operations.py
Outdated
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") |
There was a problem hiding this comment.
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.
Pull Request Test Coverage Report for Build 7878233005Details
💛 - Coveralls |
There was a problem hiding this 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
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") |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
Exposing
GEOSDisjointSubsetUnion
asdisjoint_subset_union
anddisjoint_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