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
Add compat for unpickling shapely<2 geometries #1657
Conversation
@zhengwy888 maybe you can test with your nested pickle objects and see if it works for you. |
Nice! That looks like a good solution for this upgrade issue. |
OK! I’d like to have a test for each geometry type, before merging. |
I can also add some additional tests if you didn't start yet |
Yes please! I want to focus on the pygeos py3.11 release (if I can find the time) |
I updated the test file so you can use it to create pickle files for all geometry types and for different versions of shapely. I then ran this for shapely 1.8.5 (with GEOS 3.10.3), shapely 1.8.0 (with GEOS 3.9.1) and shapely 1.7.1 (with GEOS 3.8.0), all installed using pip wheels (so the GEOS versions are the ones included in those wheels). In practice, the pickled bytes turned out to be exactly equal bit-for-bit, except for empty polygon for shapely 1.7.1 (at which point empty polygon was converted to WKB for empty 3D polygon). So I only included the files for 1.8.5, except for empty polygon. Now, in practice, since 1.7.1 was saving empty polygon as 3D WKB, I don't think we can "recover" that correctly, since we only have the WKB to use. So will probably relax the test in that case, or just remove it. I did include a fix to correctly unpickle LinearRings (so they come back as LinearRing instead of LineString) |
tests/test_pickle.py
Outdated
if geom_type == "emptypolygon" and "1.7.1" in fname.name: | ||
expected = wkt.loads("POLYGON Z EMPTY") |
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 could also just leave out this case from the files (so just test with the generated pickle data from 1.8.5)
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.
That would be fine with me! I think these tests are already pretty thorough.
And my test above appears to be obsolete now? Feel free to remove it
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.
Yes, cleaned up
Pull Request Test Coverage Report for Build 3669443448
💛 - Coveralls |
@caspervdw thanks a lot, this is good to still have included after all! |
Closes #1613
I think it is good to have a temporary compatibility fix for shapely <2.0 pickles.
This in essence makes the
Geometry
subclasses mutable through their__setstate__
, which I think is OK when only done right after construction. As a temporary measure.