Skip to content

[GH-2070] Geopandas.GeoSeries: Implement get_geometry - #2071

Merged
jiayuasu merged 6 commits into
apache:masterfrom
petern48:get_geometry_series
Jul 12, 2025
Merged

jiayuasu merged 6 commits into
apache:masterfrom
petern48:get_geometry_series

Conversation

@petern48

@petern48 petern48 commented Jul 8, 2025

Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

Implement get_geometry

How was this patch tested?

Added tests

Did this PR include necessary documentation updates?

  • Yes, I have updated the documentation.

@petern48
petern48 marked this pull request as ready for review July 8, 2025 23:11
@petern48
petern48 requested a review from jiayuasu as a code owner July 8, 2025 23:11
@petern48
petern48 requested a review from zhangfengcdt July 8, 2025 23:12
@petern48 petern48 changed the title [GH-2070] Geopandas.GeoSeries: Implmement get_geometry [GH-2070] Geopandas.GeoSeries: Implement get_geometry Jul 9, 2025
--------
>>> from shapely.geometry import Point, MultiPoint, GeometryCollection
>>> s = geopandas.GeoSeries(
... [

@jiayuasu jiayuasu Jul 10, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about POLYGON EMPTY?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polygon Empty isn't special, but MultiPolygon Empty is interesting, since it's a collection. Our ST_GeometryN errors when we use a negative index out of scope of the length of the Multi geometry object.

e.g

SELECT ST_GeometryN(MultiPolygon(Point(1, 1)), -2);  -- errors

SELECT ST_GeometryN(MultiPolygon(), -1);  -- errors

Geopandas returns null in this case. PostGIS also returns null in this case (the PostGIS implementation is already very different than ours since they use 1-indexing).

We can either fix this on the java Sedona level, Python dataframe level or just the geopandas level (case statement). Which do you think @jiayuasu ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I thought about it some more and decided to implement on geopandas level. I forgot the existing negative index handling logic was already implemented there.

@zhangfengcdt zhangfengcdt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the sheply 1 still has issue with one of the tests

@jiayuasu

jiayuasu commented Jul 11, 2025 •

Copy link
Copy Markdown
Member

@petern48 I am fine dropping Shapely 1.x support in the next Sedona major release. What do you think? @Kontinuation

@petern48

Copy link
Copy Markdown
Member Author

We don't necessarily have to drop support for shapely 1 in all of sedona if you don't want to. We could also just drop it for geopandas specifically, or skip this test for shapely 1 and accept the difference. Of course, updating documentation however necessary. Dropping support would make my life easier, but it's probably not necessarily at this point.

Looking at the error output, it looks like shapely 1, automatically interprets Polygon() as GEOMETRY COLLECTION.

        expected = gpd.GeoSeries(
            [
                Point(0, 0),
                Point(0, 0),
                MultiPoint([(0, 0), (1, 1), (0, 1), (1, 0)]),
                Polygon(),
                None,
            ]
        )

From the logs: (idk why it's formatted this way, but GeometryCollection Empty corresponds to the Polygon() object)

expected = 0                              POINT (0.00000 0.00000)
1                              POINT (0.00000 0.00000)
2    MUL...                        GEOMETRYCOLLECTION EMPTY
4                                                 None

@petern48

Copy link
Copy Markdown
Member Author

I personally think it's reasonable to just skip the test for shapely < 2.0.0 and update the docs about the behavior. Pushed a change. What do you think?

@jiayuasu jiayuasu added this to the sedona-1.8.0 milestone Jul 12, 2025
@jiayuasu
jiayuasu merged commit 5cf9e60 into apache:master Jul 12, 2025
Subham-KRLX pushed a commit to Subham-KRLX/sedona that referenced this pull request Jul 17, 2025
…#2071)

* Implement get_geometry

* Skip test for old versions

* Support extra-negative indices

* Skip test for shapely < 2.0.0

* Update docs to mention the shapely < 2.0.0 behavior
@petern48
petern48 deleted the get_geometry_series branch July 20, 2025 01:43
Kontinuation pushed a commit to Kontinuation/sedona that referenced this pull request Jan 21, 2026
…#2071)

* Implement get_geometry

* Skip test for old versions

* Support extra-negative indices

* Skip test for shapely < 2.0.0

* Update docs to mention the shapely < 2.0.0 behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Geopandas.GeoSeries: Implmement get_geometry

3 participants