diff --git a/CHANGES.md b/CHANGES.md index 744b3619..2eca8d48 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # CHANGELOG +## 0.9.1 (yyyy-mm-dd) + +### Bug fixes + +- Silence warning from `write_dataframe` with `GeoSeries.notna()` (#435). + ## 0.9.0 (2024-06-17) ### Improvements diff --git a/pyogrio/geopandas.py b/pyogrio/geopandas.py index 10be32ea..71fddcad 100644 --- a/pyogrio/geopandas.py +++ b/pyogrio/geopandas.py @@ -520,7 +520,10 @@ def write_dataframe( # If there is data, infer layer geometry type + promote_to_multi if not df.empty: # None/Empty geometries sometimes report as Z incorrectly, so ignore them - has_z_arr = geometry[geometry.notna() & (~geometry.is_empty)].has_z + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", r"GeoSeries\.notna", UserWarning) + geometry_notna = geometry.notna() + has_z_arr = geometry[geometry_notna & (~geometry.is_empty)].has_z has_z = has_z_arr.any() all_z = has_z_arr.all() diff --git a/pyogrio/tests/test_geopandas_io.py b/pyogrio/tests/test_geopandas_io.py index a8a7b94c..9da98cf2 100644 --- a/pyogrio/tests/test_geopandas_io.py +++ b/pyogrio/tests/test_geopandas_io.py @@ -2,6 +2,7 @@ from datetime import datetime from io import BytesIO import locale +import warnings import numpy as np import pytest @@ -1062,6 +1063,21 @@ def test_write_empty_dataframe(tmp_path, ext, use_arrow): assert_geodataframe_equal(df, expected) +def test_write_empty_geometry(tmp_path): + expected = gp.GeoDataFrame({"x": [0]}, geometry=from_wkt(["POINT EMPTY"]), crs=4326) + filename = tmp_path / "test.gpkg" + + # Check that no warning is raised with GeoSeries.notna() + with warnings.catch_warnings(): + warnings.simplefilter("error", UserWarning) + write_dataframe(expected, filename) + assert filename.exists() + + # Xref GH-436: round-tripping possible with GPKG but not others + df = read_dataframe(filename) + assert_geodataframe_equal(df, expected) + + @pytest.mark.parametrize("ext", [".geojsonl", ".geojsons"]) @pytest.mark.requires_arrow_write_api def test_write_read_empty_dataframe_unsupported(tmp_path, ext, use_arrow):