Skip to content

[GH-2377] test is_closed on all geo types - #2387

Merged
jiayuasu merged 4 commits into
apache:masterfrom
yunchipang:fix-geopandas-is_closed
Oct 12, 2025
Merged

jiayuasu merged 4 commits into
apache:masterfrom
yunchipang:fix-geopandas-is_closed

Conversation

@yunchipang

Copy link
Copy Markdown
Contributor

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

Expands test_is_closed to cover all geometry types, not just LineString/LinearRing, to ensure compliance with the documented behavior.

How was this patch tested?

Tests added

Did this PR include necessary documentation updates?

  • Yes, I have updated the documentation.

@petern48 petern48 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.

LGTM, pending CI passing.

@petern48

Copy link
Copy Markdown
Member

I can't trigger CI to run myself, so we'll have to wait for @jiayuasu

@jiayuasu

Copy link
Copy Markdown
Member

I can't trigger CI to run myself, so we'll have to wait for @jiayuasu

It's probably the time to make you a Sedona committer😊 @petern48

@petern48

Copy link
Copy Markdown
Member

This failure is unrelated.

   unknown package:
        Expected sha256 
6f1242f872dc33d3b4269dcaebf1838a359f9097e1cc848b0e11367bce010e4d
             Got        
a8d15178943c4e5de93d1b057c060bcaf9f3f3e37723e5c6bbac5719472c8926

I filed #2388

@petern48

petern48 commented Oct 11, 2025 •

Copy link
Copy Markdown
Member

But look at that. Glad I caught it in #2386 (comment)

FAILED tests/geopandas/test_match_geopandas_series.py::TestMatchGeopandasSeries::test_is_closed - AssertionError: Series are different

Series values are different (100.0 %)
[index]: [0, 1, 2]
[left]:  [True, True, True]
[right]: [False, False, False]

We can fix this using a SQL CASE statement.

SELECT
    CASE
        WHEN ST_GeometryType(column) = 'ST_LINESTRING` THEN ST_Closed(column)
        ELSE false
    END

ST_GeometryType() should return 'ST_LINESTRINGinstead ofST_LINEARRING, so there's no need to specify LINEARRING`.

Could you try translating this fix to Spark @yunchipang? You can look at boundary as an example of how to implement a similar case statement. Feel free to ping if you get stuck.

def boundary(self) -> "GeoSeries":
# Geopandas and shapely return NULL for GeometryCollections, so we handle it separately
# https://shapely.readthedocs.io/en/stable/reference/shapely.boundary.html
spark_expr = F.when(
stf.GeometryType(self.spark.column).isin(["GEOMETRYCOLLECTION"]),
None,
).otherwise(stf.ST_Boundary(self.spark.column))
return self._query_geometry_column(
spark_expr,
)

@petern48

Copy link
Copy Markdown
Member

Just in case you didn't know, you can set up pre-commit to run automatically after each of your local commits by running pre-commit install from the root dir.

Super optional. Some people don't like it since it takes some time to run. I personally do use it, since I always forget to run it myself. Zero problem if you don't want to, but I figured I would mention it as an FYI.

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: Implement is_closed

3 participants