Skip to content

Commit

Permalink
Issue #599/#571 Make geopandas optional dependency again
Browse files Browse the repository at this point in the history
improve docs around that too
  • Loading branch information
soxofaan committed Jul 24, 2024
1 parent 4b8593c commit f7ee552
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ For example:
- ``pyarrow`` for (read/write) support of Parquet files
(e.g. with :py:class:`~openeo.extra.job_management.MultiBackendJobManager`)
- ``rioxarray`` for GeoTIFF support in the assert helpers from ``openeo.testing.results``
- ``geopandas`` for working with dataframes with geospatial support,
(e.g. with :py:class:`~openeo.extra.job_management.MultiBackendJobManager`)


Enabling additional features
Expand Down
15 changes: 12 additions & 3 deletions openeo/extra/job_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pathlib import Path
from typing import Callable, Dict, NamedTuple, Optional, Union

import geopandas
import pandas as pd
import requests
import shapely.errors
Expand Down Expand Up @@ -540,6 +539,10 @@ class CsvJobDatabase(JobDatabaseInterface):
:implements: :py:class:`JobDatabaseInterface`
:param path: Path to local CSV file.
.. note::
Support for GeoPandas dataframes depends on the ``geopandas`` package
as :ref:`optional dependency <installation-optional-dependencies>`.
.. versionadded:: 0.31.0
"""
def __init__(self, path: Union[str, Path]):
Expand All @@ -562,6 +565,8 @@ def read(self) -> pd.DataFrame:
and df["geometry"].dtype.name != "geometry"
and self._is_valid_wkt(df["geometry"].iloc[0])
):
import geopandas

# `df.to_csv()` in `persist()` has encoded geometries as WKT, so we decode that here.
df = geopandas.GeoDataFrame(df, geometry=geopandas.GeoSeries.from_wkt(df["geometry"]))
return df
Expand All @@ -578,11 +583,14 @@ class ParquetJobDatabase(JobDatabaseInterface):
:implements: :py:class:`JobDatabaseInterface`
:param path: Path to the Parquet file.
.. versionadded:: 0.31.0
.. note::
Support for Parquet files depends on the ``pyarrow`` package
as :ref:`optional dependency <installation-optional-dependencies>`.
Support for GeoPandas dataframes depends on the ``geopandas`` package
as :ref:`optional dependency <installation-optional-dependencies>`.
.. versionadded:: 0.31.0
"""
def __init__(self, path: Union[str, Path]):
self.path = Path(path)
Expand All @@ -601,6 +609,7 @@ def read(self) -> pd.DataFrame:

metadata = pyarrow.parquet.read_metadata(self.path)
if b"geo" in metadata.metadata:
import geopandas
return geopandas.read_parquet(self.path)
else:
return pd.read_parquet(self.path)
Expand Down

0 comments on commit f7ee552

Please sign in to comment.