Skip to content

Commit

Permalink
Merge pull request #354 from jrbourbeau/inline-array-attrs
Browse files Browse the repository at this point in the history
Ensure `inline_array` keeps attributes
  • Loading branch information
martindurant authored Aug 25, 2023
2 parents 8ebc8e3 + de9eadb commit 9c6309b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions kerchunk/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ def test_inline_array():
""",
"data/0": b"\x01\x00\x00\x00",
"data/1": b"\x02\x00\x00\x00",
"data/.zattrs": '{"foo": "bar"}',
}
fs = fsspec.filesystem("reference", fo=refs)
out1 = kerchunk.utils.inline_array(refs, threshold=1000) # does nothing
assert out1 == refs
out2 = kerchunk.utils.inline_array(refs, threshold=1000, names=["data"]) # explicit
assert "data/1" not in out2
assert out2["data/.zattrs"] == refs["data/.zattrs"]
fs = fsspec.filesystem("reference", fo=out2)
g = zarr.open(fs.get_mapper())
assert g.data[:].tolist() == [1, 2]
Expand Down
4 changes: 3 additions & 1 deletion kerchunk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def _inline_array(group, threshold, names, prefix=""):
cond1 = threshold and thing.nbytes < threshold and thing.nchunks > 1
cond2 = prefix1 in names
if cond1 or cond2:
group.create_dataset(
original_attrs = dict(thing.attrs)
arr = group.create_dataset(
name=name,
dtype=thing.dtype,
shape=thing.shape,
Expand All @@ -184,6 +185,7 @@ def _inline_array(group, threshold, names, prefix=""):
compression=None,
overwrite=True,
)
arr.attrs.update(original_attrs)


def inline_array(store, threshold=1000, names=None, remote_options=None):
Expand Down

0 comments on commit 9c6309b

Please sign in to comment.