Skip to content

Commit

Permalink
FIX: silence warning from write_dataframe with GeoSeries.notna() (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews authored Jul 2, 2024
1 parent 33d32ec commit d82974c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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

0 comments on commit d82974c

Please sign in to comment.