DEPR: actually deprecate cascaded_union in favor of unary_union (#2074)

This commit is contained in:
Joris Van den Bossche
2021-08-23 20:41:38 +01:00
committed by GitHub
parent d006fad416
commit befb2e88da
3 changed files with 18 additions and 4 deletions
+7 -3
View File
@@ -6,7 +6,6 @@ from pandas import DataFrame, Series
from shapely.geometry import box
from shapely.geometry.base import BaseGeometry
from shapely.ops import cascaded_union
from .array import GeometryArray, GeometryDtype
@@ -699,8 +698,13 @@ GeometryCollection
@property
def cascaded_union(self):
"""Deprecated: Return the unary_union of all geometries"""
return cascaded_union(np.asarray(self.geometry.values))
"""Deprecated: use `unary_union` instead"""
warn(
"The 'cascaded_union' attribute is deprecated, use 'unary_union' instead",
FutureWarning,
stacklevel=2,
)
return self.geometry.values.unary_union()
@property
def unary_union(self):
+10
View File
@@ -350,6 +350,16 @@ class TestGeomMethods:
self._test_unary_topological("unary_union", expected, g)
def test_cascaded_union_deprecated(self):
p1 = self.t1
p2 = Polygon([(2, 0), (3, 0), (3, 1)])
g = GeoSeries([p1, p2])
with pytest.warns(
FutureWarning, match="The 'cascaded_union' attribute is deprecated"
):
result = g.cascaded_union
assert result == g.unary_union
def test_contains(self):
expected = [True, False, True, False, False, False, False]
assert_array_dtype_equal(expected, self.g0.contains(self.t1))
+1 -1
View File
@@ -476,7 +476,7 @@ def test_groupby(df):
assert_frame_equal(res, exp)
# applying on the geometry column
res = df.groupby("value2")["geometry"].apply(lambda x: x.cascaded_union)
res = df.groupby("value2")["geometry"].apply(lambda x: x.unary_union)
if compat.PANDAS_GE_11:
exp = GeoSeries(
[shapely.geometry.MultiPoint([(0, 0), (2, 2)]), Point(1, 1)],