Skip to content

COMPAT: avoid using shapely.geos for recent shapely versions #542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jorisvandenbossche
Copy link
Member

Avoiding a deprecation warning about accessing shapely.geos with shapely >= 2.1

Comment on lines +8 to +9
if shapely.__version__ < "2.0.0":
import shapely.geos
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not very explicit with what versions we support for optional dependencies, but if we assume only shapely>=2 usage, this extra import could also be removed.

It might actually be that with shapely 2, we can remove this try/except import of shapely altogether, since it no longer uses a ctypes/cython mix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we extend the policy we have in geopandas, then according to SPEC0 we should support only shapely 2.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the peanut gallery -- shapely > 2.0 is a great idea -- keeping old cruft around is a burden on maintenance. 2.0 was released over three years ago -- it's time :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main problem is that we can't really check this or raise an error, because shapely is only an optional dependency, and at import time of pyogrio, we don't know if the user is going to use shapely or not (and python does not have such an optional dependency constraints in installation metadata).

So of course we can just remove this and thus remove the shapely<2 support. But that means if someone for whatever reason is still using that older version of shapely together with latest pyogrio, they would potentially get very strange, hard to debug errors or segfaults.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this logic it could be there forever. Within the same try/except you can check for shapely version and raise an informative error before it comes to segfaults.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would vote for something more like:

    if shapely.__version__ < "2.0.0":
        raise RunTimeError("shapely version >= 2 is required")

if it's still in the try block, then it would only get raised if they have shapely installed.

I suppose they could still not use shapely -- in which case, maybe a warning instead?

    if shapely.__version__ < "2.0.0":
        warnings.warn("shapely version >= 2 is required if you use shapely functionality")

would it really segfault without the import on shapely < 2? that seems pretty broken -- but we have what we have.

import shapely.geos # noqa: F401

if shapely.__version__ < "2.0.0":
import shapely.geos
except Exception:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm --shouldn't this be: except ImportError: ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants