tomalrussell / snkit

spatial networks toolkit (python)
MIT License
31 stars 10 forks source link

Annoying `ShapelyDeprecationWarning` #52

Closed jmon12 closed 2 years ago

jmon12 commented 2 years ago

Description

Using recent versions of shapely (here 1.8.2), every time snkit.network.split_edge_at_points is used, the following warning is shown:

ShapelyDeprecationWarning: GeometryTypeError will derive from ShapelyError and not TypeError or ValueError in Shapely 2.0.
  raise GeometryTypeError("Splitting a LineString with a %s is not supported" % splitter.type)

This relates to the attempts to harmonize the handling of errors in shapely, see the related issue. I didn't find anything related in geopandas issues.

Investigation and potential solutions

For shapely >= 1.8, it seems that the correct usage would be using except GeometryTypeError (to verify), but this is problematic in terms of requirements:

The current solution is to catch the warning:

import warnings
from shapely.errors import ShapelyDeprecationWarning

with warnings.catch_warnings():
    warnings.filterwarnings('ignore', category=ShapelyDeprecationWarning)
    # ...

Conclusions

The problem would be solved upstream when geopandas increments the shapely requirements. But even so, I don't think it is worth a higher geopandas requirements, e.g. geopandas >=0.12.

What are the possibilities?

jmon12 commented 2 years ago

Hum I just saw that catching the warnings is already used in network.py, e.g. in geoms_to_array... I probably had a too strict vision of what direct dependencies are.

I will add warning filters when it is safe and necessary for similar shapely deprecation warnings.