Skip to content

[GH-3393] Preserve empty multipart members in Python serde - #3394

Merged
jiayuasu merged 2 commits into
apache:masterfrom
jiayuasu:codex/python-serde-empty-members
Sep 23, 2026
Merged

jiayuasu merged 2 commits into
apache:masterfrom
jiayuasu:codex/python-serde-empty-members

Conversation

@jiayuasu

@jiayuasu jiayuasu commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

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 transform feature; #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:

PYTHONPATH=python python -m pytest -p no:cacheprovider \
  python/tests/utils/test_geomserde_speedup.py \
  python/tests/utils/test_geometry_serde_empty.py -q
  • Shapely 2.1.2 / GEOS 3.13.1: 164 passed.
  • Shapely 2.0.0 / GEOS 3.11.1: 130 passed, 34 skipped.
  • Shapely 1.8.5.post1 / GEOS 3.10.3: 123 passed, 41 skipped.

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_empty explicitly, 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, and equals_exact for 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.deserializeMultiPoint treats 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.

@jiayuasu jiayuasu added this to the sedona-2.0.0 milestone Sep 23, 2026
@jiayuasu
jiayuasu merged commit b0f9b24 into apache:master Sep 23, 2026
34 checks passed
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.

Python geometry deserialization drops or changes empty multipart members

1 participant