diff --git a/geopandas/base.py b/geopandas/base.py index f489157..19acae9 100644 --- a/geopandas/base.py +++ b/geopandas/base.py @@ -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): diff --git a/geopandas/tests/test_geom_methods.py b/geopandas/tests/test_geom_methods.py index f9c0afe..a617dc3 100644 --- a/geopandas/tests/test_geom_methods.py +++ b/geopandas/tests/test_geom_methods.py @@ -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)) diff --git a/geopandas/tests/test_pandas_methods.py b/geopandas/tests/test_pandas_methods.py index cd29605..3267313 100644 --- a/geopandas/tests/test_pandas_methods.py +++ b/geopandas/tests/test_pandas_methods.py @@ -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)],