Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: silence warning from write_dataframe with GeoSeries.notna() #435

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion pyogrio/geopandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
16 changes: 16 additions & 0 deletions pyogrio/tests/test_geopandas_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime
from io import BytesIO
import locale
import warnings

import numpy as np
import pytest
Expand Down Expand Up @@ -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):
Expand Down
Loading