Skip to content

Commit

Permalink
FIX: silence warning from write_dataframe with GeoSeries.notna()
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews committed Jun 26, 2024
1 parent af292e5 commit db6161c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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
13 changes: 13 additions & 0 deletions pyogrio/tests/test_geopandas_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,19 @@ 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()
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):
Expand Down

0 comments on commit db6161c

Please sign in to comment.