Skip to content

Commit

Permalink
Compat with dask 2022.06.0: fix schema inference in to_parquet (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Jun 19, 2022
1 parent 5fe927f commit 82da8f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions dask_geopandas/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from geopandas.array import GeometryArray, GeometryDtype, from_shapely

DASK_2021_06_0 = Version(dask.__version__) >= Version("2021.06.0")
DASK_2022_06_0 = Version(dask.__version__) >= Version("2022.06.0")

if DASK_2021_06_0:
from dask.dataframe.dispatch import make_meta_dispatch
Expand All @@ -22,6 +23,8 @@
from dask.dataframe.core import make_meta as make_meta_dispatch
from dask.dataframe.utils import _nonempty_index, meta_nonempty_dataframe

if DASK_2022_06_0:
from dask.dataframe.dispatch import pyarrow_schema_dispatch

from .core import GeoSeries, GeoDataFrame

Expand Down Expand Up @@ -70,3 +73,16 @@ def tokenize_geometryarray(x):
# TODO if we can find an efficient hashing function (eg hashing integer
# pointers on the C level?), we could replace this random uuid
return uuid.uuid4().hex


if DASK_2022_06_0:

@pyarrow_schema_dispatch.register((geopandas.GeoDataFrame,))
def get_pyarrow_schema_geopandas(obj):
import pyarrow as pa
import pandas as pd

df = pd.DataFrame(obj.copy())
for col in obj.columns[obj.dtypes == "geometry"]:
df[col] = obj[col].to_wkb()
return pa.Schema.from_pandas(df)
2 changes: 1 addition & 1 deletion dask_geopandas/io/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _pandas_to_arrow_table(
# TODO add support for schema
# (but let it already pass if the passed schema would not change the result)
if schema is not None:
if not table.schema.equals(schema):
if not table.schema.equals(schema) and len(df):
raise NotImplementedError("Passing 'schema' is not yet supported")

return table
Expand Down

0 comments on commit 82da8f1

Please sign in to comment.