Skip to content

Commit d57ab95

Browse files
Copilotsoxofaan
andcommitted
Add clarifying comments addressing code review feedback
Explain cross-version compatibility requirements for annotation strings and dtype conversion logic Co-authored-by: soxofaan <44946+soxofaan@users.noreply.github.com>
1 parent 60f6e07 commit d57ab95

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

openeo/extra/job_management/_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ def normalize_df(self, df: pd.DataFrame) -> pd.DataFrame:
9494
"""
9595
new_columns = {col: req.default for (col, req) in self._requirements.items() if col not in df.columns}
9696
df = df.assign(**new_columns)
97-
# Apply dtype conversions to ensure compatibility with pandas 3's stricter type checking
98-
# This is especially important for columns that may contain NaN values but need to be strings
97+
# Apply dtype conversions to ensure compatibility with pandas 3's stricter type checking.
98+
# This is especially important for columns that may contain NaN values but need to be strings.
99+
# We only convert columns with specific dtype requirements (e.g., "str", "float64").
100+
# Columns with dtype="object" are skipped because "object" is pandas' flexible catch-all type.
99101
dtype_conversions = {}
100102
for col, req in self._requirements.items():
101103
if col in df.columns and req.dtype != "object":

openeo/udf/run_code.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,14 @@ def _get_annotation_str(annotation: Union[str, type]) -> str:
7878

7979
def _annotation_is_pandas_series(annotation) -> bool:
8080
# Support both pandas 2.x ("pandas.core.series.Series") and pandas 3.x ("pandas.Series")
81+
# We explicitly list both paths to ensure cross-version compatibility:
82+
# - UDFs written with pandas 2.x annotations should work in pandas 3.x environments
83+
# - UDFs written with pandas 3.x annotations should work in pandas 2.x environments
8184
return annotation in {
8285
pandas.Series,
83-
_get_annotation_str(pandas.Series),
84-
"pandas.core.series.Series", # Legacy pandas 2.x path
85-
"pandas.Series", # pandas 3.x path
86+
_get_annotation_str(pandas.Series), # Current pandas version's path
87+
"pandas.core.series.Series", # Explicit pandas 2.x path for cross-version support
88+
"pandas.Series", # Explicit pandas 3.x path for cross-version support
8689
}
8790

8891

0 commit comments

Comments
 (0)