This is an automated email from the ASF dual-hosted git repository.
jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/master by this push:
new 120313107f [GH-2134] Fix bug where get_crs logic won't work if first
element is null (#2135)
120313107f is described below
commit 120313107f387dcd88b10408727c0f94a96be48f
Author: Peter Nguyen <[email protected]>
AuthorDate: Tue Jul 22 11:21:40 2025 -0700
[GH-2134] Fix bug where get_crs logic won't work if first element is null
(#2135)
---
python/sedona/geopandas/geoseries.py | 13 +++++++++----
python/tests/geopandas/test_geoseries.py | 7 +++++++
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/python/sedona/geopandas/geoseries.py
b/python/sedona/geopandas/geoseries.py
index f038b9693c..6e33c9e40e 100644
--- a/python/sedona/geopandas/geoseries.py
+++ b/python/sedona/geopandas/geoseries.py
@@ -493,12 +493,17 @@ class GeoSeries(GeoFrame, pspd.Series):
if len(self) == 0:
return None
- tmp = self._process_geometry_column("ST_SRID", rename="crs",
returns_geom=False)
- ps_series = tmp.take([0])
- srid = ps_series.iloc[0]
+ tmp_series: pspd.Series = self._process_geometry_column(
+ "ST_SRID", rename="crs", returns_geom=False
+ )
+
+ # All geometries should have the same srid
+ # so we just take the srid of the first non-null element
+ first_idx = tmp_series.first_valid_index()
+ srid = tmp_series[first_idx] if first_idx is not None else 0
# Sedona returns 0 if doesn't exist
- return CRS.from_user_input(srid) if srid != 0 and not pd.isna(srid)
else None
+ return CRS.from_user_input(srid) if srid != 0 else None
@crs.setter
def crs(self, value: Union["CRS", None]):
diff --git a/python/tests/geopandas/test_geoseries.py
b/python/tests/geopandas/test_geoseries.py
index e3621da080..0c2dc97831 100644
--- a/python/tests/geopandas/test_geoseries.py
+++ b/python/tests/geopandas/test_geoseries.py
@@ -1341,3 +1341,10 @@ class TestGeoSeries(TestGeopandasBase):
geo_series = sgpd.GeoSeries(self.geoseries, crs=4326)
assert geo_series.crs.to_epsg() == 4326
+
+ # This test errors due to a bug in pyspark.
+ # We can uncomment it once the fix is
https://github.com/apache/spark/pull/51475 is merged
+ # It was tested locally by using the fixed version of pyspark
+ # # First element null
+ # geo_series = sgpd.GeoSeries([None, None, Point(1, 1)], crs=4326)
+ # assert geo_series.crs.to_epsg() == 4326