Repository navigation
[GH-3393] Preserve empty multipart members in Python serde - #3394
Merged
jiayuasu merged 2 commits intoSep 23, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Did you read the Contributor Guide?
Yes. Read the Contributor Rules and Contributor Development Guide.
Is this PR related to a ticket?
Closes #3393.
This is the serde prerequisite extracted from #3389. It can be reviewed and merged independently of the GeoPandas
transformfeature; #3389 should land afterward.What changes were proposed in this PR?
Preserve empty members when Python decodes multipart geometries. For example,
MULTIPOINT (EMPTY, (1 2), EMPTY)must retain three members with emptiness flags[True, False, True]after a round trip.The pure-Python fallback currently discards empty MultiPoint, MultiLineString, and MultiPolygon members. Reconstruct multipart values containing empty members through a shared WKB helper to retain their positions and supported coordinate layouts. Normal multipart values retain their existing constructor path. Points with only one NaN XY ordinate remain nonempty.
The native MultiPoint decoder currently assumes NaN coordinates create an empty point. GEOS 3.13 creates nonempty NaN points through these constructors, so construct stored empty points with a zero-length coordinate sequence while preserving their XY/XYZ/XYM/XYZM layout. Nonempty 2D points retain the fast path.
These are existing deserialization bugs. The wire format and public API are unchanged; this PR contains only the two serde implementation files, three test files, and a release note.
How was this patch tested?
Rebuilt the native CPython 3.11 extension from this branch and confirmed each test run loaded that extension. Ran both complete modules:
mvn spotless:apply,git diff --check, and all applicable commit hooks passed.The compatibility skips cover unsupported layouts/features. Tests cover member positions, all-empty and zero-member collections, supported coordinate layouts, SRIDs, consumed byte offsets, and partially NaN points. Native tests assert
is_emptyexplicitly, since WKB alone cannot distinguish the affected NaN points from empty points.The existing 35-case Spark serde compatibility test now checks multipart member counts, each member's
is_empty, andequals_exactfor nonempty members in all three directions: Python round trip, Python-to-JVM, and JVM-to-Python. This detects both dropped members and nonempty NaN points that topological.equals()accepts. All 35 passed with the native extension, and all 35 passed with the Python fallback on Spark 4.1.2 / Shapely 2.1.2 / GEOS 3.13.1. The fallback run disabled the native extension on both driver and workers. The same 35 cases passed with Shapely 1.8.5.post1 / GEOS 3.10.3 and the native extension.The strengthened assertion was also verified to reject all three baseline fallback failures and the native NaN-point failure while the previous
.equals()assertion accepted them.The original combined branch reproduced the two Spark transform failures before this native fix and passed all six multipart integration cases afterward. The standalone branch has no dependency on the transform implementation. GEOS 3.8 has not been tested locally.
CI evidence on commit
740f3792b5, before the assertion-only follow-up: the Shapely 1.8.5 job passed its two test selections (1722 passed, 787 skipped and 530 passed, 2 skipped). CI for the assertion follow-up is tracked separately on the latest commit.Known pre-existing JVM difference:
GeometrySerializer.deserializeMultiPointtreats a member with NaN X alone as empty, while Python's native decoder already preserved(NaN, 1)and both Python decoders now require NaN in both X and Y. JVM-written empty members contain NaN in both ordinates and decode correctly. Aligning the JVM's handling of partially NaN points is a separate follow-up; this PR does not change that rule.Did this PR include necessary documentation updates?
Yes. Added a Python bug-fix release note. No public API documentation change is required.