Deprecate len(..) of multi-part geometries#1075
Deprecate len(..) of multi-part geometries#1075jorisvandenbossche merged 3 commits intoshapely:masterfrom
Conversation
|
@jorisvandenbossche |
|
Yes, as long as we keep the |
|
Personally I agree with your initial thought @jorisvandenbossche, |
mwtoews
left a comment
There was a problem hiding this comment.
Changes look good, and I agree there is no need for a .ngeoms property.
Other than suggested edits, the manual can be adjusted slightly too:
- https://github.com/Toblerity/Shapely/blob/master/docs/manual.rst#collections-of-polygons - remove the two lines around "len(polygons)"
- https://github.com/Toblerity/Shapely/blob/master/docs/manual.rst#constructive-methods adjust
len(clean)->len(clean.geoms) - https://github.com/Toblerity/Shapely/blob/master/docs/manual.rst#merging-linear-features adjust
len(result)->len(result.geoms)
xref #932
PR #950 already deprecated
__getitem__and__iter__of multi-part geometries, but not yet__len__.Similarly to that deprecation, users can do
len(obj.geoms)instead oflen(obj). We could also add a.ngeomsproperty as a shortcut for this, if that is desired.Note that I think deprecating
__len__is not strictly needed for compatibility with numpy (although I would need to check this to be sure), as long as the geometries are not iterable anymore (or have an array_interface). Personally I think it follows a bit from deprecating getitem/iter, where__len__typically is implemented for collection-like objects (and which multi-part geometries no longer are in Shapely 2.0). So I am fine with deprecating it (you also need to know if you have a multi-part geometry or not before calling it, sincelen(point)currently fails, so if you already know that, it shouldn't be any problem to do eglen(multipoint.geoms)instead).But, we could also keep
__len__if people prefer that. Speaking in terms of the python ABCs (https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes), multi-part geometries could be "Sized" without being "Iterable" / a "Collection".