jiayuasu opened a new issue, #3293:
URL: https://github.com/apache/sedona/issues/3293
## Expected behavior
Constructing a Sedona GeoDataFrame from an existing GeoPandas GeoDataFrame
should succeed without changing the caller-owned GeoPandas object.
## Actual behavior
On the supported Spark 3.4 / pandas 1.5 / GeoPandas 0.13 dependency lane, a
GeoPandas input with MultiIndex columns can be mutated during construction. Its
active geometry column is converted from `GeometryDtype` to `object`, after
which construction fails while reading `data.crs`:
```text
AttributeError: The CRS attribute of a GeoDataFrame without an active
geometry column is not defined.
```
The constructor builds `pd.DataFrame(data, copy=False)` and then casts
geometry columns to `object` for Spark. Under pandas 1.5, the shallow frame can
share blocks with `data`, so that cast mutates the caller's GeoDataFrame.
PR #3289 avoids this path for its local `from_dict`/`from_features`
conversion helper by passing `copy=True`, but the public
`GeoDataFrame(existing_geopandas_frame)` constructor still has the underlying
behavior.
## Steps to reproduce
```python
import geopandas as gpd
from shapely.geometry import Point
from sedona.spark.geopandas import GeoDataFrame
data = {
"index": ["row-b", "row-a"],
"columns": [["shape", "geometry"], ["attr", "name"]],
"data": [[None, "first"], [Point(1.0, 2.0), "second"]],
"index_names": ["row"],
"column_names": ["kind", "field"],
}
local = gpd.GeoDataFrame.from_dict(
data,
orient="tight",
geometry=("shape", "geometry"),
crs="EPSG:4326",
)
assert str(local.dtypes.iloc[0]) == "geometry"
GeoDataFrame(local)
```
The fix should ensure the caller-owned frame and its geometry/CRS metadata
remain unchanged while Sedona converts its own copy to Spark-compatible object
columns. A regression should exercise the direct constructor on the oldest
supported pandas/GeoPandas lane.
## Environment
- Sedona: `master` / `2.0.0-SNAPSHOT`
- Apache Spark: 3.4.0
- Scala: 2.12
- JRE: 11
- Python: 3.8.13
- pandas: 1.5.3
- GeoPandas: 0.13.2
- Shapely: 1.8.5
- API: Python, Sedona GeoPandas API
- Runtime: local Spark
## Existing issues
I searched the existing issues and did not find a duplicate.
--
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]