Skip to content

Commit

Permalink
Drop support for pyarrow<0.16 (#108)
Browse files Browse the repository at this point in the history
Co-authored-by: George Sakkis <[email protected]>
  • Loading branch information
gsakkis and gsakkis authored Mar 2, 2023
1 parent a858a28 commit 64a573c
Showing 1 changed file with 1 addition and 51 deletions.
52 changes: 1 addition & 51 deletions spatialpandas/io/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

from .. import GeoDataFrame
from ..dask import DaskGeoDataFrame
from ..geometry import (GeometryDtype, LineDtype, MultiLineDtype,
MultiPointDtype, MultiPolygonDtype,
PointDtype, PolygonDtype, RingDtype)
from ..geometry.base import to_geometry_array
from ..geometry import GeometryDtype
from ..io.utils import (
PathType,
_maybe_prepend_protocol,
Expand All @@ -32,20 +29,6 @@
# improve pandas compatibility, based on geopandas _compat.py
PANDAS_GE_12 = Version(pd.__version__) >= Version("1.2.0")

_geometry_dtypes = [
PointDtype, MultiPointDtype, RingDtype, LineDtype,
MultiLineDtype, PolygonDtype, MultiPolygonDtype
]


def _import_geometry_columns(df, geom_cols):
new_cols = {}
for col, type_str in geom_cols.items():
if col in df and not isinstance(df.dtypes[col], GeometryDtype):
new_cols[col] = to_geometry_array(df[col], dtype=type_str)

return df.assign(**new_cols)


def _load_parquet_pandas_metadata(
path,
Expand Down Expand Up @@ -84,24 +67,6 @@ def _load_parquet_pandas_metadata(
)


def _get_geometry_columns(pandas_metadata):
columns = pandas_metadata.get('columns', [])
geom_cols = {}
for col in columns:
type_string = col.get('numpy_type', None)
is_geom_col = False
for geom_type in _geometry_dtypes:
try:
geom_type.construct_from_string(type_string)
is_geom_col = True
except TypeError:
pass
if is_geom_col:
geom_cols[col["name"]] = col["numpy_type"]

return geom_cols


def to_parquet(
df: GeoDataFrame,
path: PathType,
Expand Down Expand Up @@ -180,11 +145,6 @@ def read_parquet(
**kwargs,
).read(columns=columns).to_pandas()

# Import geometry columns, not needed for pyarrow >= 0.16
geom_cols = _get_geometry_columns(metadata)
if geom_cols:
df = _import_geometry_columns(df, geom_cols)

# Return result
return GeoDataFrame(df)

Expand Down Expand Up @@ -409,16 +369,6 @@ def _perform_read_parquet_dask(
**engine_kwargs,
)._meta

# Import geometry columns in meta, not needed for pyarrow >= 0.16
metadata = _load_parquet_pandas_metadata(
paths[0],
filesystem=filesystem,
storage_options=storage_options,
engine_kwargs=engine_kwargs,
)
geom_cols = _get_geometry_columns(metadata)
if geom_cols:
meta = _import_geometry_columns(meta, geom_cols)
meta = GeoDataFrame(meta)

# Handle geometry in meta
Expand Down

0 comments on commit 64a573c

Please sign in to comment.