jiayuasu commented on code in PR #1052:
URL: https://github.com/apache/sedona-db/pull/1052#discussion_r3654772545


##########
python/sedonadb-geopandas/python/sedonadb_geopandas/__init__.py:
##########
@@ -0,0 +1,51 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""GeoPandas-compatible API on top of SedonaDB.
+
+This package provides :class:`GeoDataFrame` / :class:`GeoSeries` wrappers whose
+methods mirror GeoPandas but delegate to a lazy SedonaDB engine. It is a
+compatibility layer, not a drop-in replacement: see the package README for the
+intentional differences (laziness, no row index, immutability).
+"""
+
+from sedonadb_geopandas._context import default_context
+from sedonadb_geopandas._frame import GeoDataFrame
+from sedonadb_geopandas._series import GeoSeries, Series
+
+__all__ = ["GeoDataFrame", "GeoSeries", "Series", "from_geopandas"]
+
+
+def from_geopandas(data, *, context=None, geometry=None):
+    """Load a ``geopandas.GeoDataFrame`` into a SedonaDB-backed 
``GeoDataFrame``.
+
+    Args:
+        data: A ``geopandas.GeoDataFrame`` (or any object accepted by

Review Comment:
   Fixed — converted the docstrings across the package from reST (double 
backticks, `:class:` roles) to markdown.



##########
python/sedonadb-geopandas/python/sedonadb_geopandas/_frame.py:
##########
@@ -0,0 +1,90 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""GeoPandas-style GeoDataFrame backed by a lazy SedonaDB frame."""
+
+from sedonadb_geopandas._series import GeoSeries, Series
+
+
+class GeoDataFrame:
+    """A lazy SedonaDB frame in the shape of a ``geopandas.GeoDataFrame``.
+
+    Wraps a SedonaDB ``DataFrame`` and tracks the active geometry column.
+    Row selection, column access, and geometry operations mirror GeoPandas but
+    build a query rather than computing eagerly; call ``to_geopandas()`` to
+    materialize.
+    """
+
+    def __init__(self, df, geometry="geometry"):
+        self._df = df
+        self._geometry_name = geometry
+
+    @property
+    def geometry(self):
+        """The active geometry column as a :class:`GeoSeries`."""
+        return GeoSeries(self._df, self._df[self._geometry_name], 
self._geometry_name)
+
+    @property
+    def crs(self):
+        """The CRS of the active geometry column (via a zero-row 
materialization)."""
+        return self._df.limit(0).to_pandas().crs
+
+    @property
+    def columns(self):
+        """Column names, mirroring ``GeoDataFrame.columns``."""
+        return list(self._df.schema.names)
+
+    def __getitem__(self, key):
+        # Boolean mask -> row filter (gdf[gdf["pop"] > 1000]).
+        if isinstance(key, Series):
+            return GeoDataFrame(self._df.filter(key._expr), 
self._geometry_name)
+
+        # Column subset -> GeoDataFrame (keeps the geometry column if 
selected).
+        if isinstance(key, list):
+            return GeoDataFrame(self._df.select(*key), self._geometry_name)
+
+        # Single column -> (Geo)Series.
+        if isinstance(key, str):
+            expr = self._df[key]
+            if key == self._geometry_name:
+                return GeoSeries(self._df, expr, key)
+            return Series(self._df, expr, key)
+
+        raise TypeError(
+            f"GeoDataFrame indices must be a column name, list of names, or "
+            f"boolean mask, not {type(key).__name__}"
+        )
+
+    def to_crs(self, crs):
+        """Reproject the geometry column to ``crs`` (``ST_Transform``)."""
+        from sedonadb.expr import lit
+
+        transformed = 
self._df[self._geometry_name].geo.transform(lit(str(crs)))
+        new_df = self._df.mutate(**{self._geometry_name: transformed})
+        return GeoDataFrame(new_df, self._geometry_name)
+
+    def to_geopandas(self):
+        """Execute and return a ``geopandas.GeoDataFrame``."""
+        return self._df.to_pandas()
+
+    # Alias: results carry geometry, so this returns a GeoDataFrame too.
+    to_pandas = to_geopandas

Review Comment:
   Handled. The active geometry column is `None` when the frame has none, 
`.crs` returns `None`, `.geometry` raises a clear `AttributeError`, and a 
column subset re-derives the geometry column instead of carrying a stale name — 
so a pipeline that drops geometry and later re-adds it behaves. A test covers 
the dropped-geometry case.



##########
python/sedonadb-geopandas/pyproject.toml:
##########
@@ -0,0 +1,50 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+[build-system]
+requires = ["hatchling"]
+build-backend = "hatchling.build"
+
+[project]
+name = "sedonadb-geopandas"
+version = "0.4.0"
+description = "GeoPandas-compatible API on top of SedonaDB"
+readme = "README.md"
+requires-python = ">=3.9"
+dependencies = [

Review Comment:
   Fixed — hard dependencies are now `sedonadb`, `sedonadb-expr` (for the 
`.geo` accessor), and `pyarrow` (for literals). `geopandas` moved to an 
optional extra, since it is only needed for the `from_geopandas` / 
`to_geopandas` interop helpers.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to