petern48 commented on code in PR #2130:
URL: https://github.com/apache/sedona/pull/2130#discussion_r2220564226
##########
python/sedona/geopandas/geoseries.py:
##########
@@ -4074,29 +4058,40 @@ def clip(self, mask, keep_geom_type: bool = False,
sort=False) -> "GeoSeries":
# # Utils
#
-----------------------------------------------------------------------------
- def get_first_geometry_column(self) -> str:
- first_binary_or_geometry_col = next(
- (
- field.name
- for field in self._internal.spark_frame.schema.fields
- if isinstance(field.dataType, BinaryType)
- or field.dataType.typeName() == "geometrytype"
- ),
- None,
- )
- if first_binary_or_geometry_col:
- return first_binary_or_geometry_col
+ def _update_inplace(self, result: "GeoSeries"):
+ self.rename(result.name, inplace=True)
+ self._update_anchor(result._anchor)
- raise ValueError(
- "get_first_geometry_column: No geometry column found in the
GeoSeries."
- )
+ # TODO: remove this method and call _get_series_col_name directly
+ def get_first_geometry_column(self) -> str:
+ return _get_series_col_name(self)
# -----------------------------------------------------------------------------
# # Utils
# -----------------------------------------------------------------------------
+def _get_series_col_name(ps_series: pspd.Series) -> str:
+ series_name = ps_series.name if ps_series.name else
SPARK_DEFAULT_SERIES_NAME
+ spark_col_names = set(ps_series._internal.spark_frame.columns)
+
+ if series_name in spark_col_names:
+ return series_name
+ # Combining different frames (e.g in the GeoDataFrame.setitem method adds
these prefixes
+ # It's easier to check for them at read time than rename them at write time
+ # For GeoDataFrame.setitem, the left ("this") side if not overridden, so
we always prefer the right ("that") side
+ # which is why it needs to come first in the if/elif/else sequence
+ elif f"__that_{series_name}" in spark_col_names:
+ return f"__that_{series_name}"
+ elif f"__this_{series_name}" in spark_col_names:
+ return f"__this_{series_name}"
Review Comment:
I've decided to take a different approach that will allow us to avoid ugly
code like this in https://github.com/apache/sedona/pull/2131
--
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]