-
Notifications
You must be signed in to change notification settings - Fork 0
Switch to _ARRAY_DIMENSIONS for xarray #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
} | ||
|
||
|
||
def dataset_to_icechunk(ds: Dataset, store: "IcechunkStore") -> None: | ||
async def dataset_to_icechunk_async(ds: Dataset, store: "IcechunkStore") -> None: | ||
""" | ||
Write an xarray dataset whose variables wrap ManifestArrays to an Icechunk store. | ||
|
||
|
@@ -52,13 +52,17 @@ def dataset_to_icechunk(ds: Dataset, store: "IcechunkStore") -> None: | |
# root_group.attrs = ds.attrs | ||
for k, v in ds.attrs.items(): | ||
root_group.attrs[k] = encode_zarr_attr_value(v) | ||
|
||
return await write_variables_to_icechunk_group( | ||
ds.variables, | ||
store=store, | ||
group=root_group, | ||
) | ||
|
||
|
||
def dataset_to_icechunk(ds: Dataset, store: "IcechunkStore") -> None: | ||
asyncio.run( | ||
write_variables_to_icechunk_group( | ||
ds.variables, | ||
store=store, | ||
group=root_group, | ||
) | ||
dataset_to_icechunk_async(ds=ds, store=store) | ||
) | ||
|
||
|
||
|
@@ -113,12 +117,13 @@ async def write_virtual_variable_to_icechunk( | |
zarray = ma.zarray | ||
|
||
# creates array if it doesn't already exist | ||
codecs = zarray._v3_codec_pipeline() | ||
arr = group.require_array( | ||
name=name, | ||
shape=zarray.shape, | ||
chunk_shape=zarray.chunks, | ||
dtype=encode_dtype(zarray.dtype), | ||
codecs=zarray._v3_codec_pipeline(), | ||
#codecs=codecs, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the codec pipeline stuff not work at all? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently crashing when zlib is included. I'm gunna wait till the next cut of zarr v3 to try again there |
||
dimension_names=var.dims, | ||
fill_value=zarray.fill_value, | ||
# TODO fill_value? | ||
|
@@ -127,7 +132,7 @@ async def write_virtual_variable_to_icechunk( | |
# TODO it would be nice if we could assign directly to the .attrs property | ||
for k, v in var.attrs.items(): | ||
arr.attrs[k] = encode_zarr_attr_value(v) | ||
arr.attrs["DIMENSION_NAMES"] = encode_zarr_attr_value(var.dims) | ||
arr.attrs["_ARRAY_DIMENSIONS"] = encode_zarr_attr_value(var.dims) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did I just make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure haha but this is what xarray needs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Zarr V3 actual has native support for dimension names, but it's not supported in Xarray yet. So put a flag that we should change this eventually. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are just going to have both for now with this pr. |
||
|
||
_encoding_keys = {"_FillValue", "missing_value", "scale_factor", "add_offset"} | ||
for k, v in var.encoding.items(): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't changing this without changing the test break the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't change this, extracted it and made both async and sync versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes - sorry I couldn't see that easily when I looked from my phone haha