mattijn / topojson

Encode spatial data as topology in Python! 🌍 https://mattijn.github.io/topojson
BSD 3-Clause "New" or "Revised" License
176 stars 27 forks source link

Shapely deprecation warnings in topojson 1.3 #145

Closed bakaleks closed 2 years ago

bakaleks commented 2 years ago

Hi. Deprecation warnings from Shapely 1.8.0 has started to appear after upgrade to topojson 1.3

.venv/lib/python3.8/site-packages/shapely/geometry/base.py:250: ShapelyDeprecationWarning: Setting the 'coords' to mutate a Geometry in place is deprecated, and will not be possible any more in Shapely 2.0

.venv/lib/python3.8/site-packages/topojson/core/topology.py:482: ShapelyDeprecationWarning: The array interface is deprecated and will no longer work in Shapely 2.0. Convert the '.coords' to a numpy array instead.

.venv/lib/python3.8/site-packages/topojson/core/extract.py:332: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use thegeomsproperty to access the constituent parts of a multi-part geometry.

.venv/lib/python3.8/site-packages/topojson/core/extract.py:301: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of thegeomsproperty instead to get the number of parts of a multi-part geometry.

mattijn commented 2 years ago

Thanks for raising the issue! Yes, this will require some work. Also will have to check if the suggested changes are backwards compatible with shapely versions prior 1.8.0

bakaleks commented 2 years ago

Maybe you can put upper limits on dependency versions? https://github.com/mattijn/topojson/blob/master/pyproject.toml#L17

mattijn commented 2 years ago

Logging to self:

from shapely import geometry
feat = {
    "type": "Feature",
    "geometry": {"type": "LineString", "coordinates": [[0.1, 0.2], [0.3, 0.4]]},
}

geometry.shape(feat)
/Users/mattijnvanhoek/miniconda3/lib/python3.9/site-packages/shapely/geometry/geo.py:123: ShapelyDeprecationWarning: GeometryTypeError will derive from ShapelyError and not TypeError or ValueError in Shapely 2.0.
  raise GeometryTypeError("Unknown geometry type: %s" % geom_type)
---------------------------------------------------------------------------
GeometryTypeError                         Traceback (most recent call last)
/var/folders/2c/mjc91yxs03s45rz21c8crzv40000gn/T/ipykernel_12563/2908707415.py in <module>
      5 }
      6 
----> 7 geometry.shape(feat)

~/miniconda3/lib/python3.9/site-packages/shapely/geometry/geo.py in shape(context)
    121         return GeometryCollection(geoms)
    122     else:
--> 123         raise GeometryTypeError("Unknown geometry type: %s" % geom_type)
    124 
    125 

GeometryTypeError: Unknown geometry type: feature

I include a from shapely.errors import ShapelyError and catch this error as well now (https://github.com/mattijn/topojson/commit/5e7bc7252a62d26345bc48433a79d8665533d29d), but I do not think this will make the warning disappear until shapely 2.0

mattijn commented 2 years ago

I still have more warning stating the following:

  <__array_function__ internals>:5: ShapelyDeprecationWarning: The array interface is deprecated and will no longer work in Shapely 2.0. Convert the '.coords' to a numpy array instead.

Where is this <__array_function__ internals>:5 located πŸ€”?? Not sure how to approach this one.

mattijn commented 2 years ago

With PR #158 all code creating deprecation warnings are changed. Current master holds no warnings anymore for the test suite. Thanks for posting this issue, but I'm closing it😊.