spatialdata icon indicating copy to clipboard operation
spatialdata copied to clipboard

Bug with pygeos makes sjoin fail

Open LucaMarconato opened this issue 1 year ago • 1 comments

If incompatible versions of pygeos, geopandas and shapely are installed one may encounter bugs with geopandas or reduced performance. In an extreme case I just saw sjoin fail with the following error:

...
  File "/Users/macbook/miniconda3/envs/ome/lib/python3.11/site-packages/pygeos/decorators.py", line 80, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/macbook/miniconda3/envs/ome/lib/python3.11/site-packages/pygeos/predicates.py", line 159, in is_empty
    return lib.is_empty(geometry, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: One of the arguments is of incorrect type. Please provide only Geometry objects.

We should investigate better which versions of shapely, geopandas and pygeos are compatible and we recommend and report the incompatible versions to the developers of the respective libraries.

A workaround in case this happens is to add this in the code before import geopandas, shapely or pygeos

# isort: off
import os

# os.environ["USE_PYGEOS"] = "0"
# isort:on

or to set the following in bash before running the code

export USE_PYGEOS=0

LucaMarconato avatar May 19 '23 21:05 LucaMarconato

Thank you for this issue, had the same problem and not using pygeos solved the problem, amazing.

lopollar avatar Jul 04 '23 12:07 lopollar

Fixed with https://github.com/scverse/spatialdata/pull/545

LucaMarconato avatar May 24 '24 16:05 LucaMarconato