From 24e1a882d9b46649b96a89e14ff35ea742ba0322 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Wed, 26 Jun 2024 23:00:02 +1200 Subject: [PATCH 1/3] FIX: silence warning from write_dataframe with GeoSeries.notna() --- pyogrio/geopandas.py | 5 ++++- pyogrio/tests/test_geopandas_io.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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..94977a9d 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.shp" + + # Check that no warning is raised with GeoSeries.notna() + with warnings.catch_warnings(): + warnings.simplefilter("error", UserWarning) + write_dataframe(expected, filename) + assert filename.exists() + + # TODO: fix reading POINT EMPTY + # 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): From 0ab83cf44900d29432c6a57175025cb6635710d1 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Tue, 2 Jul 2024 18:52:48 +1200 Subject: [PATCH 2/3] PR feedback, use GPKG for round-tripping and add comment --- pyogrio/tests/test_geopandas_io.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyogrio/tests/test_geopandas_io.py b/pyogrio/tests/test_geopandas_io.py index 94977a9d..9da98cf2 100644 --- a/pyogrio/tests/test_geopandas_io.py +++ b/pyogrio/tests/test_geopandas_io.py @@ -1065,7 +1065,7 @@ def test_write_empty_dataframe(tmp_path, ext, use_arrow): def test_write_empty_geometry(tmp_path): expected = gp.GeoDataFrame({"x": [0]}, geometry=from_wkt(["POINT EMPTY"]), crs=4326) - filename = tmp_path / "test.shp" + filename = tmp_path / "test.gpkg" # Check that no warning is raised with GeoSeries.notna() with warnings.catch_warnings(): @@ -1073,9 +1073,9 @@ def test_write_empty_geometry(tmp_path): write_dataframe(expected, filename) assert filename.exists() - # TODO: fix reading POINT EMPTY - # df = read_dataframe(filename) - # assert_geodataframe_equal(df, expected) + # 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"]) From ea875b978e91ad79d6c13ca552e163688c81ad93 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Tue, 2 Jul 2024 18:57:34 +1200 Subject: [PATCH 3/3] Add CHANGELOG entry --- CHANGES.md | 6 ++++++ 1 file changed, 6 insertions(+) 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