Skip to content

Commit 8a7a73b

Browse files
Update kerchunk writer refs_to_dataframe to deal with ArrowStringArray from new ZarrParser deps. (zarr-developers#907)
* adds new zarr parser deps and fix to acccessor * adds pandas dep to kerchunk writer
1 parent 3287d82 commit 8a7a73b

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ all_parsers = [
8282
icechunk = [
8383
"icechunk>=1.1.2",
8484
]
85-
kerchunk = ["fastparquet"]
85+
zarr = ["arro3-core", "pyarrow"]
86+
87+
kerchunk = ["fastparquet", "pandas"]
8688

8789
all_writers = [
8890
"virtualizarr[icechunk]",

virtualizarr/accessor.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,27 @@ def to_kerchunk(
192192

193193
return None
194194
elif format == "parquet":
195+
import pandas as pd
195196
from kerchunk.df import refs_to_dataframe
196197

197198
if isinstance(filepath, Path):
198199
url = str(filepath)
199200
elif isinstance(filepath, str):
200201
url = filepath
201202

202-
# refs_to_dataframe is responsible for writing to parquet.
203-
# at no point does it create a full in-memory dataframe.
204-
refs_to_dataframe(
205-
refs,
206-
url=url,
207-
record_size=record_size,
208-
categorical_threshold=categorical_threshold,
209-
)
203+
# The zarr-parser performance update PR #892 adds pyarrow and arro3-core as deps.
204+
# These break the `kerchunk` refs_to_dataframe behavior.
205+
# It seems like pyarrow makes pandas default to an ArrowStringArray
206+
# which fastparquet cannot zero-copy encode.
207+
# TODO: remove once fastparquet or kerchunk handle ArrowStringArray.
208+
209+
with pd.option_context("future.infer_string", False):
210+
refs_to_dataframe(
211+
refs,
212+
url=url,
213+
record_size=record_size,
214+
categorical_threshold=categorical_threshold,
215+
)
210216
return None
211217
else:
212218
raise ValueError(f"Unrecognized output format: {format}")

0 commit comments

Comments
 (0)