Repository navigation
[GH-3124] Preserve GeoSeries indexes in to_geoframe - #3538
Merged
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, I have read the Contributor Rules and Contributor Development Guide.
Is this PR related to a ticket?
Related to #3124. This is an independent GeoPandas fix used by #3391; it does not close the Spark native spatial support issue and does not depend on native types or the spatial type predicate PR.
What changes were proposed in this PR?
GeoSeries.to_geoframe()currently converts through a Spark DataFrame using one physical index column name. A series with a MultiIndex therefore fails with a mismatch between its two index levels and the one supplied index name.Construct the GeoDataFrame directly from the series' existing pandas-on-Spark InternalFrame. This retains index levels and names, duplicate labels, null geometry values, CRS metadata and pending column expressions. Existing default and explicit geometry-column naming are preserved. Remove the now-unused single-index constant and update a stale test comment.
The change is limited to two Python files and works with the existing Sedona UDT implementation. It changes no serializer or spatial execution path.
How was this patch tested?
Validated commit
457518688539544090a885308ef50f79291a5b91.pytest -q tests/geopandas/test_geoseries.py -k to_geoframe_preserves: all eight focused cases passed on Spark 4.1. Coverage compares full collected GeoDataFrames with GeoPandas and checks source preservation, duplicate axes, nulls, CRS, geometry naming, and lazy expressions with pending aliases.eaca7639f2ed7b754951af5d64a5deeed1cec5cdwithmvn -o -B -Dspark=4.1 -Dspark.version=4.1.1 -Dscala=2.13 -Dgeotools -Dmaven.javadoc.skip=true -Dmaven.jar.forceCreation=true -pl spark-shaded -am -DskipTests clean install.test_geoseries.pyandtest_geodataframe.pyrun passed 516 tests; four others stopped in the isolated launcher because Spark was initialized before the test fixture's SparkContext property. InitializingTestBase.scfirst made all four pass, together with all eight new cases (12 passed). No repository workaround or skip was added. All 520 selected cases therefore passed across the full run and focused rerun.Did this PR include necessary documentation updates?
No new API is introduced. The existing
to_geoframenaming contract remains unchanged, and the test comment claiming MultiIndex was unsupported is updated alongside the new regression coverage.