diff --git a/geopandas/geodataframe.py b/geopandas/geodataframe.py index 3b4b516..1545c3b 100644 --- a/geopandas/geodataframe.py +++ b/geopandas/geodataframe.py @@ -189,11 +189,10 @@ class GeoDataFrame(GeoPandasBase, DataFrame): self.set_geometry(geometry, inplace=True) if geometry is None and crs: - warnings.warn( - "Assigning CRS to a GeoDataFrame without a geometry column is now " - "deprecated and will not be supported in the future.", - FutureWarning, - stacklevel=2, + raise ValueError( + "Assigning CRS to a GeoDataFrame without a geometry column is not " + "supported. Supply geometry using the 'geometry=' keyword argument, " + "or by providing a DataFrame with column name 'geometry'", ) def __setattr__(self, attr, val): @@ -442,13 +441,11 @@ class GeoDataFrame(GeoPandasBase, DataFrame): def crs(self, value): """Sets the value of the crs""" if self._geometry_column_name not in self: - warnings.warn( - "Assigning CRS to a GeoDataFrame without a geometry column is now " - "deprecated and will not be supported in the future.", - FutureWarning, - stacklevel=4, + raise ValueError( + "Assigning CRS to a GeoDataFrame without a geometry column is not " + "supported. Use GeoDataFrame.set_geometry to set the active " + "geometry column.", ) - self._crs = None if not value else CRS.from_user_input(value) else: if hasattr(self.geometry.values, "crs"): self.geometry.values.crs = value diff --git a/geopandas/tests/test_crs.py b/geopandas/tests/test_crs.py index 2b995e4..04a4270 100644 --- a/geopandas/tests/test_crs.py +++ b/geopandas/tests/test_crs.py @@ -242,9 +242,13 @@ class TestGeometryArrayCRS: assert df.geometry.crs == self.wgs assert df.geometry.values.crs == self.wgs - df = GeoDataFrame(self.geoms, columns=["geom"], crs=27700) - assert df.crs == self.osgb - df = df.set_geometry("geom") + with pytest.raises(ValueError, match="Assigning CRS to a GeoDataFrame without"): + GeoDataFrame(self.geoms, columns=["geom"], crs=27700) + with pytest.raises(ValueError, match="Assigning CRS to a GeoDataFrame without"): + GeoDataFrame(crs=27700) + + df = GeoDataFrame(self.geoms, columns=["geom"]) + df = df.set_geometry("geom", crs=27700) assert df.crs == self.osgb assert df.geometry.crs == self.osgb assert df.geometry.values.crs == self.osgb @@ -256,14 +260,8 @@ class TestGeometryArrayCRS: assert df.geometry.crs == self.osgb assert df.geometry.values.crs == self.osgb - df = GeoDataFrame(crs=27700) - df = df.set_geometry(self.geoms) - assert df.crs == self.osgb - assert df.geometry.crs == self.osgb - assert df.geometry.values.crs == self.osgb - # new geometry with set CRS has priority over GDF CRS - df = GeoDataFrame(crs=27700) + df = GeoDataFrame(geometry=self.geoms, crs=27700) df = df.set_geometry(self.geoms, crs=4326) assert df.crs == self.wgs assert df.geometry.crs == self.wgs @@ -341,14 +339,18 @@ class TestGeometryArrayCRS: "scalar", [None, Point(0, 0), LineString([(0, 0), (1, 1)])] ) def test_scalar(self, scalar): - with pytest.warns(FutureWarning): - df = GeoDataFrame() - df.crs = 4326 + df = GeoDataFrame() df["geometry"] = scalar + df.crs = 4326 assert df.crs == self.wgs assert df.geometry.crs == self.wgs assert df.geometry.values.crs == self.wgs + def test_crs_with_no_geom_fails(self): + with pytest.raises(ValueError, match="Assigning CRS to a GeoDataFrame without"): + df = GeoDataFrame() + df.crs = 4326 + def test_read_file(self): nybb_filename = datasets.get_path("nybb") df = read_file(nybb_filename) @@ -579,21 +581,6 @@ class TestGeometryArrayCRS: assert merged.geom.values.crs == self.osgb assert merged.crs == self.osgb - # CRS should be assigned to geometry - def test_deprecation(self): - with pytest.warns(FutureWarning): - df = GeoDataFrame([], crs=27700) - - # https://github.com/geopandas/geopandas/issues/1548 - # ensure we still have converted the crs value to a CRS object - assert isinstance(df.crs, pyproj.CRS) - - with pytest.warns(FutureWarning): - df = GeoDataFrame([]) - df.crs = 27700 - - assert isinstance(df.crs, pyproj.CRS) - # make sure that geometry column from list has CRS (__setitem__) def test_setitem_geometry(self): arr = from_shapely(self.geoms, crs=27700)