Skip to content

Commit 88fd131

Browse files
authored
Merge pull request #659 from Carreau/copy_attrs
Copy also attributes on root in copy_all
2 parents da4f790 + aa41b1f commit 88fd131

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

docs/release.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ This release will be the first release of Zarr not supporting Python 3.5.
1313
* Add `Array` tests for FSStore.
1414
By :user:`Andrew Fulton <andrewfulton9>`; :issue: `644`.
1515

16+
* fix a bug in which ``attrs`` would not be copied on the root when using ``copy_all``; :issue:`613`
17+
1618
2.5.0
1719
-----
1820

zarr/convenience.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,7 @@ def copy_all(source, dest, shallow=False, without_attrs=False, log=None,
10651065
n_copied += c
10661066
n_skipped += s
10671067
n_bytes_copied += b
1068+
dest.attrs.update(**source.attrs)
10681069

10691070
# log a final message with a summary of what happened
10701071
_log_copy_summary(log, dry_run, n_copied, n_skipped, n_bytes_copied)

zarr/tests/test_convenience.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,18 @@
99
from numcodecs import Adler32, Zlib
1010
from numpy.testing import assert_array_equal
1111

12-
from zarr.convenience import (consolidate_metadata, copy, copy_store, load,
13-
open, open_consolidated, save, save_group)
12+
import zarr
13+
from zarr.convenience import (
14+
consolidate_metadata,
15+
copy,
16+
copy_store,
17+
load,
18+
open,
19+
open_consolidated,
20+
save,
21+
save_group,
22+
copy_all,
23+
)
1424
from zarr.core import Array
1525
from zarr.errors import CopyError
1626
from zarr.hierarchy import Group, group
@@ -421,6 +431,31 @@ def check_copied_group(original, copied, without_attrs=False, expect_props=None,
421431
assert sorted(original.attrs.items()) == sorted(copied.attrs.items())
422432

423433

434+
def test_copy_all():
435+
"""
436+
https://github.com/zarr-developers/zarr-python/issues/269
437+
438+
copy_all used to not copy attributes as `.keys()` does not return hidden `.zattrs`.
439+
440+
"""
441+
original_group = zarr.group(store=MemoryStore(), overwrite=True)
442+
original_group.attrs["info"] = "group attrs"
443+
original_subgroup = original_group.create_group("subgroup")
444+
original_subgroup.attrs["info"] = "sub attrs"
445+
446+
destination_group = zarr.group(store=MemoryStore(), overwrite=True)
447+
448+
# copy from memory to directory store
449+
copy_all(
450+
original_group,
451+
destination_group,
452+
dry_run=False,
453+
)
454+
455+
assert destination_group.attrs["info"] == "group attrs"
456+
assert destination_group.subgroup.attrs["info"] == "sub attrs"
457+
458+
424459
# noinspection PyAttributeOutsideInit
425460
class TestCopy(unittest.TestCase):
426461

0 commit comments

Comments
 (0)