Preserve precision grid size when copying geometries by apoorva-01 · Pull Request #2465 · shapely/shapely · GitHub
Skip to content

Preserve precision grid size when copying geometries#2465

Open
apoorva-01 wants to merge 1 commit into
shapely:mainfrom
apoorva-01:fix/2073-preserve-precision-on-copy
Open

Preserve precision grid size when copying geometries#2465
apoorva-01 wants to merge 1 commit into
shapely:mainfrom
apoorva-01:fix/2073-preserve-precision-on-copy

Conversation

@apoorva-01

@apoorva-01 apoorva-01 commented Jul 2, 2026

Copy link
Copy Markdown

deepcopy and pickle lose the precision grid size from set_precision (get_precision comes back 0.0). The reduce methods only store WKB, and WKB doesn't carry the grid size.

So I stash get_precision next to the WKB and re-apply it on unpickle. Regression test in test_misc.py, plus a CHANGES entry. Suite's green.

One call I'd like your take on: @jorisvandenbossche noted set_precision might change the geometry, and it does for polygons. The default mode renormalizes the ring start vertex (geometry's still equal, just a different starting point) but keeps Z and M. mode="pointwise" avoids that but drops M, so I went with the default to not lose data. Fine as is, or would you rather have a lower-level grid-size setter?

Fixes #2073

deepcopy and pickle went through WKB only, which drops the grid size set
by set_precision. Store it alongside the WKB and re-apply it on load.
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.

deepcopy() looses the precision property if set

1 participant