mirror of
https://github.com/wassname/geopandas.git
synced 2026-09-12 12:20:25 +08:00
DEPR: actually deprecate cascaded_union in favor of unary_union (#2074)
This commit is contained in:
+7
-3
@@ -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):
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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)],
|
||||
|
||||
Reference in New Issue
Block a user