Repository: geopandas/geopandas
Pull request #2447 (2022-06-03 12:20:45)

MAINT: switch old deprecationwarnings to futurewarnings
Left this a little too late I suspect (was on my list a while ago but slipped off), but thought I'd put up anyway since getting this into a release will speed up when the final deprecations can actually happen.

xref #2263 


Patch:
diff --git a/geopandas/geodataframe.py b/geopandas/geodataframe.py
index 0f3f780d..d6444e28 100644
--- a/geopandas/geodataframe.py
+++ b/geopandas/geodataframe.py
@@ -1864,7 +1864,7 @@ individually so that features may have different properties
         warnings.warn(
             "'^' operator will be deprecated. Use the 'symmetric_difference' "
             "method instead.",
-            DeprecationWarning,
+            FutureWarning,
             stacklevel=2,
         )
         return self.geometry.symmetric_difference(other)
@@ -1873,7 +1873,7 @@ individually so that features may have different properties
         """Implement | operator as for builtin set type"""
         warnings.warn(
             "'|' operator will be deprecated. Use the 'union' method instead.",
-            DeprecationWarning,
+            FutureWarning,
             stacklevel=2,
         )
         return self.geometry.union(other)
@@ -1882,7 +1882,7 @@ individually so that features may have different properties
         """Implement & operator as for builtin set type"""
         warnings.warn(
             "'&' operator will be deprecated. Use the 'intersection' method instead.",
-            DeprecationWarning,
+            FutureWarning,
             stacklevel=2,
         )
         return self.geometry.intersection(other)
@@ -1891,7 +1891,7 @@ individually so that features may have different properties
         """Implement - operator as for builtin set type"""
         warnings.warn(
             "'-' operator will be deprecated. Use the 'difference' method instead.",
-            DeprecationWarning,
+            FutureWarning,
             stacklevel=2,
         )
         return self.geometry.difference(other)
diff --git a/geopandas/geoseries.py b/geopandas/geoseries.py
index eb9bd8e7..cc9b5fad 100644
--- a/geopandas/geoseries.py
+++ b/geopandas/geoseries.py
@@ -1245,7 +1245,7 @@ e": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": [3
         warnings.warn(
             "'^' operator will be deprecated. Use the 'symmetric_difference' "
             "method instead.",
-            DeprecationWarning,
+            FutureWarning,
             stacklevel=2,
         )
         return self.symmetric_difference(other)
@@ -1254,7 +1254,7 @@ e": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": [3
         """Implement | operator as for builtin set type"""
         warnings.warn(
             "'|' operator will be deprecated. Use the 'union' method instead.",
-            DeprecationWarning,
+            FutureWarning,
             stacklevel=2,
         )
         return self.union(other)
@@ -1263,7 +1263,7 @@ e": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": [3
         """Implement & operator as for builtin set type"""
         warnings.warn(
             "'&' operator will be deprecated. Use the 'intersection' method instead.",
-            DeprecationWarning,
+            FutureWarning,
             stacklevel=2,
         )
         return self.intersection(other)
@@ -1272,7 +1272,7 @@ e": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": [3
         """Implement - operator as for builtin set type"""
         warnings.warn(
             "'-' operator will be deprecated. Use the 'difference' method instead.",
-            DeprecationWarning,
+            FutureWarning,
             stacklevel=2,
         )
         return self.difference(other)
diff --git a/geopandas/io/file.py b/geopandas/io/file.py
index 0b55373c..9e36641b 100644
--- a/geopandas/io/file.py
+++ b/geopandas/io/file.py
@@ -269,7 +269,7 @@ def read_file(*args, **kwargs):
     warnings.warn(
         "geopandas.io.file.read_file() is intended for internal "
         "use only, and will be deprecated. Use geopandas.read_file() instead.",
-        DeprecationWarning,
+        FutureWarning,
         stacklevel=2,
     )
 
@@ -281,7 +281,7 @@ def to_file(*args, **kwargs):
         "geopandas.io.file.to_file() is intended for internal "
         "use only, and will be deprecated. Use GeoDataFrame.to_file() "
         "or GeoSeries.to_file() instead.",
-        DeprecationWarning,
+        FutureWarning,
         stacklevel=2,
     )
 
diff --git a/geopandas/io/sql.py b/geopandas/io/sql.py
index 06c00b95..93b8c188 100644
--- a/geopandas/io/sql.py
+++ b/geopandas/io/sql.py
@@ -182,7 +182,7 @@ def read_postgis(*args, **kwargs):
     warnings.warn(
         "geopandas.io.sql.read_postgis() is intended for internal "
         "use only, and will be deprecated. Use geopandas.read_postgis() instead.",
-        DeprecationWarning,
+        FutureWarning,
         stacklevel=2,
     )
 
diff --git a/geopandas/plotting.py b/geopandas/plotting.py
index 8555dccc..aa198d5c 100644
--- a/geopandas/plotting.py
+++ b/geopandas/plotting.py
@@ -11,14 +11,14 @@ from packaging.version import Version
 from ._decorator import doc
 
 
-def deprecated(new):
+def deprecated(new, warning_type=FutureWarning):
     """Helper to provide deprecation warning."""
 
     def old(*args, **kwargs):
         warnings.warn(
             "{} is intended for internal ".format(new.__name__[1:])
             + "use only, and will be deprecated.",
-            DeprecationWarning,
+            warning_type,
             stacklevel=2,
         )
         new(*args, **kwargs)


Test patch:
diff --git a/geopandas/io/tests/test_file.py b/geopandas/io/tests/test_file.py
index 2e6314e2..ec631807 100644
--- a/geopandas/io/tests/test_file.py
+++ b/geopandas/io/tests/test_file.py
@@ -261,7 +261,7 @@ def test_to_file_empty(tmpdir):
 
 def test_to_file_privacy(tmpdir, df_nybb):
     tempfilename = os.path.join(str(tmpdir), "test.shp")
-    with pytest.warns(DeprecationWarning):
+    with pytest.warns(FutureWarning):
         geopandas.io.file.to_file(df_nybb, tempfilename)
 
 
@@ -679,7 +679,7 @@ def test_read_file_empty_shapefile(tmpdir):
 
 
 def test_read_file_privacy(tmpdir, df_nybb):
-    with pytest.warns(DeprecationWarning):
+    with pytest.warns(FutureWarning):
         geopandas.io.file.read_file(geopandas.datasets.get_path("nybb"))
 
 
diff --git a/geopandas/io/tests/test_sql.py b/geopandas/io/tests/test_sql.py
index 62d832fd..360fefa6 100644
--- a/geopandas/io/tests/test_sql.py
+++ b/geopandas/io/tests/test_sql.py
@@ -326,7 +326,7 @@ class TestIO:
         create_postgis(con, df_nybb)
 
         sql = "SELECT * FROM nybb;"
-        with pytest.warns(DeprecationWarning):
+        with pytest.warns(FutureWarning):
             geopandas.io.sql.read_postgis(sql, con)
 
     def test_write_postgis_default(self, engine_postgis, df_nybb):
diff --git a/geopandas/tests/test_geom_methods.py b/geopandas/tests/test_geom_methods.py
index 705b5eb1..013dc45e 100644
--- a/geopandas/tests/test_geom_methods.py
+++ b/geopandas/tests/test_geom_methods.py
@@ -1224,39 +1224,39 @@ class TestGeomMethods:
     # Test '&', '|', '^', and '-'
     #
     def test_intersection_operator(self):
-        with pytest.warns(DeprecationWarning):
+        with pytest.warns(FutureWarning):
             self._test_binary_operator("__and__", self.t1, self.g1, self.g2)
-        with pytest.warns(DeprecationWarning):
+        with pytest.warns(FutureWarning):
             self._test_binary_operator("__and__", self.t1, self.gdf1, self.g2)
 
     def test_union_operator(self):
-        with pytest.warns(DeprecationWarning):
+        with pytest.warns(FutureWarning):
             self._test_binary_operator("__or__", self.sq, self.g1, self.g2)
-        with pytest.warns(DeprecationWarning):
+        with pytest.warns(FutureWarning):
             self._test_binary_operator("__or__", self.sq, self.gdf1, self.g2)
 
     def test_union_operator_polygon(self):
-        with pytest.warns(DeprecationWarning):
+        with pytest.warns(FutureWarning):
             self._test_binary_operator("__or__", self.sq, self.g1, self.t2)
-        with pytest.warns(DeprecationWarning):
+        with pytest.warns(FutureWarning):
             self._test_binary_operator("__or__", self.sq, self.gdf1, self.t2)
 
     def test_symmetric_difference_operator(self):
-        with pytest.warns(DeprecationWarning):
+        with pytest.warns(FutureWarning):
             self._test_binary_operator("__xor__", self.sq, self.g3, self.g4)
-        with pytest.warns(DeprecationWarning):
+        with pytest.warns(FutureWarning):
             self._test_binary_operator("__xor__", self.sq, self.gdf3, self.g4)
 
     def test_difference_series2(self):
         expected = GeoSeries([GeometryCollection(), self.t2])
-        with pytest.warns(DeprecationWarning):
+        with pytest.warns(FutureWarning):
             self._test_binary_operator("__sub__", expected, self.g1, self.g2)
-        with pytest.warns(DeprecationWarning):
+        with pytest.warns(FutureWarning):
             self._test_binary_operator("__sub__", expected, self.gdf1, self.g2)
 
     def test_difference_poly2(self):
         expected = GeoSeries([self.t1, self.t1])
-        with pytest.warns(DeprecationWarning):
+        with pytest.warns(FutureWarning):
             self._test_binary_operator("__sub__", expected, self.g1, self.t2)
-        with pytest.warns(DeprecationWarning):
+        with pytest.warns(FutureWarning):
             self._test_binary_operator("__sub__", expected, self.gdf1, self.t2)
diff --git a/geopandas/tests/test_plotting.py b/geopandas/tests/test_plotting.py
index 368a0440..26291ced 100644
--- a/geopandas/tests/test_plotting.py
+++ b/geopandas/tests/test_plotting.py
@@ -1438,8 +1438,8 @@ class TestPlotCollections:
         with pytest.raises((TypeError, ValueError)):
             _plot_point_collection(ax, self.points, color="not color")
 
-        # check DeprecationWarning
-        with pytest.warns(DeprecationWarning):
+        # check FutureWarning
+        with pytest.warns(FutureWarning):
             plot_point_collection(ax, self.points)
 
     def test_points_values(self):
@@ -1511,8 +1511,8 @@ class TestPlotCollections:
         # not a color
         with pytest.raises((TypeError, ValueError)):
             _plot_linestring_collection(ax, self.lines, color="not color")
-        # check DeprecationWarning
-        with pytest.warns(DeprecationWarning):
+        # check FutureWarning
+        with pytest.warns(FutureWarning):
             plot_linestring_collection(ax, self.lines)
 
     def test_linestrings_values(self):
@@ -1603,8 +1603,8 @@ class TestPlotCollections:
         # not a color
         with pytest.raises((TypeError, ValueError)):
             _plot_polygon_collection(ax, self.polygons, color="not color")
-        # check DeprecationWarning
-        with pytest.warns(DeprecationWarning):
+        # check FutureWarning
+        with pytest.warns(FutureWarning):
             plot_polygon_collection(ax, self.polygons)
 
     def test_polygons_values(self):