Skip to content

Commit 0d295dc

Browse files
committed
Issue #714 CsvJobDatabase: workaround GeoPandas error with column named "crs"
1 parent 946e9d1 commit 0d295dc

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121

2222
### Fixed
2323

24+
- `CsvJobDatabase`: workaround GeoPandas issue when there is a column named "crs" ([#714](https://github.com/Open-EO/openeo-python-client/issues/714))
25+
2426

2527
## [0.37.0] - 2025-01-21 - "SAP10" release
2628

openeo/extra/job_management/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,8 @@ def read(self) -> pd.DataFrame:
904904
import geopandas
905905

906906
# `df.to_csv()` in `persist()` has encoded geometries as WKT, so we decode that here.
907-
df = geopandas.GeoDataFrame(df, geometry=geopandas.GeoSeries.from_wkt(df["geometry"]))
907+
df.geometry = geopandas.GeoSeries.from_wkt(df["geometry"])
908+
df = geopandas.GeoDataFrame(df)
908909
return df
909910

910911
def persist(self, df: pd.DataFrame):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"urllib3<2.3.0", # httpretty doesn't work properly with urllib3>=2.3.0. See #700 and https://github.com/gabrielfalcao/HTTPretty/issues/484
2626
"netCDF4>=1.7.0",
2727
"matplotlib", # TODO: eliminate matplotlib as test dependency
28-
"geopandas",
28+
"geopandas>0.13.2",
2929
"flake8>=5.0.0",
3030
"time_machine",
3131
"pyproj>=3.2.0", # Pyproj is an optional, best-effort runtime dependency

tests/extra/job_management/test_job_management.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,26 @@ def test_initialize_from_df_on_exists_skip(self, tmp_path):
977977
)
978978
assert set(db.read()["some_number"]) == {1, 2, 3}
979979

980+
def test_read_with_crs_column(self, tmp_path):
981+
"""
982+
Having a column named "crs" can cause obscure error messages when creating a GeoPandas dataframe
983+
https://github.com/Open-EO/openeo-python-client/issues/714
984+
"""
985+
source_df = pd.DataFrame(
986+
{
987+
"crs": [1234],
988+
"geometry": ["Point(2 3)"],
989+
}
990+
)
991+
path = tmp_path / "jobs.csv"
992+
source_df.to_csv(path, index=False)
993+
result_df = CsvJobDatabase(path).read()
994+
assert isinstance(result_df, geopandas.GeoDataFrame)
995+
assert result_df.to_dict(orient="list") == {
996+
"crs": [1234],
997+
"geometry": [shapely.geometry.Point(2, 3)],
998+
}
999+
9801000

9811001
class TestParquetJobDatabase:
9821002

0 commit comments

Comments
 (0)