-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
base: main
Are you sure you want to change the base?
COMPAT: avoid using shapely.geos for recent shapely versions #542
Conversation
if shapely.__version__ < "2.0.0": | ||
import shapely.geos |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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:
?
Avoiding a deprecation warning about accessing
shapely.geos
with shapely >= 2.1