geopandas / pyogrio

Vectorized vector I/O using OGR
https://pyogrio.readthedocs.io
MIT License
257 stars 21 forks source link

UserWarning from geopandas' to_file() with GeoSeries.notna() #432

Closed mwtoews closed 3 hours ago

mwtoews commented 6 days ago

I'm seeing a UserWarning with geopandas-1.0.0 while using the to_file() method.

/tmp/py310/lib/python3.10/site-packages/pyogrio/geopandas.py:523: UserWarning: GeoSeries.notna() previously returned False for both missing (None) and empty geometries. Now, it only returns False for missing values. Since the calling GeoSeries contains empty geometries, the result has changed compared to previous versions of GeoPandas. Given a GeoSeries 's', you can use '~s.is_empty & s.notna()' to get back the old behaviour.

To further ignore this warning, you can do: import warnings; warnings.filterwarnings('ignore', 'GeoSeries.notna', UserWarning) has_z_arr = geometry[geometry.notna() & (~geometry.is_empty)].has_z

And checking the code here: https://github.com/geopandas/pyogrio/blob/af292e579572a6a33a22a6403873b8e7b0a9d7f6/pyogrio/geopandas.py#L523

A simple fix would be to apply the suggestion from the warning.

has_z_arr = geometry[~geometry.is_empty & geometry.notna()].has_z 
martinfleis commented 6 days ago

Thanks!

The snippet won't fix it as it just inverts the order of conditions but notna() will emit the warning anyway. We shall suppress the warning here.

mwtoews commented 6 days ago

Thanks for the tips, makes sense to follow the second suggestion. I can prepare a test and PR for this one.