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 179c87cadf [GH-2062] Fix failing Geopandas tests after recent PR 
merges (#2063)
179c87cadf is described below

commit 179c87cadf2e57858841b095495abe0b0930ef0c
Author: Peter Nguyen <petern0...@gmail.com>
AuthorDate: Sat Jul 5 21:10:24 2025 -0700

    [GH-2062] Fix failing Geopandas tests after recent PR merges (#2063)
    
    * Convert to wkb for ps.Series case and don't pass self.crs in to_geopandas
    
    * Catch np.nan for .crs
---
 python/sedona/geopandas/geoseries.py | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/python/sedona/geopandas/geoseries.py 
b/python/sedona/geopandas/geoseries.py
index 805b827fb8..f7ad400806 100644
--- a/python/sedona/geopandas/geoseries.py
+++ b/python/sedona/geopandas/geoseries.py
@@ -140,8 +140,23 @@ class GeoSeries(GeoFrame, pspd.Series):
             # This is NOT a scalable solution since we call to_pandas() on the 
data and is a hacky solution
             # but this should be resolved if/once 
https://github.com/apache/spark/pull/51300 is merged in.
             # For now, we reset self._anchor = data to have keep the geometry 
information (e.g crs) that's lost in to_pandas()
+
+            pd_data = data.to_pandas()
+
+            # If has shapely geometries, convert to wkb since 
pandas-on-pyspark can't understand shapely geometries
+            if (
+                isinstance(pd_data, pd.Series)
+                and any(isinstance(x, BaseGeometry) for x in pd_data)
+            ) or (
+                isinstance(pd_data, pd.DataFrame)
+                and any(isinstance(x, BaseGeometry) for x in 
pd_data.values.ravel())
+            ):
+                pd_data = pd_data.apply(
+                    lambda geom: geom.wkb if geom is not None else None
+                )
+
             super().__init__(
-                data=data.to_pandas(),
+                data=pd_data,
                 index=index,
                 dtype=dtype,
                 name=name,
@@ -214,7 +229,7 @@ class GeoSeries(GeoFrame, pspd.Series):
         tmp_df = self._process_geometry_column("ST_SRID", rename="crs")
         srid = tmp_df.take([0])[0]
         # Sedona returns 0 if doesn't exist
-        return CRS.from_user_input(srid) if srid else None
+        return CRS.from_user_input(srid) if srid != 0 and not pd.isna(srid) 
else None
 
     @crs.setter
     def crs(self, value: Union["CRS", None]):

Reply via email to