Skip to content

Commit 4ab6b3f

Browse files
authored
fix sync group constructors (#1652)
1 parent 6f61e92 commit 4ab6b3f

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/zarr/v3/codecs/bytes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BytesCodecConfigurationMetadata:
2929
@frozen
3030
class BytesCodecMetadata:
3131
configuration: BytesCodecConfigurationMetadata
32-
name: Literal["bytes"] = field(default="bytes", init=False)
32+
name: Literal["bytes"] = field(default="bytes", init=True)
3333

3434

3535
@frozen

src/zarr/v3/group.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
from zarr.v3.common import ZARR_JSON, ZARRAY_JSON, ZATTRS_JSON, ZGROUP_JSON, make_cattr
1313
from zarr.v3.config import RuntimeConfiguration, SyncConfiguration
1414
from zarr.v3.store import StoreLike, StorePath, make_store_path
15-
from zarr.v3.sync import SyncMixin
15+
from zarr.v3.sync import SyncMixin, sync
1616

1717
logger = logging.getLogger("zarr.group")
1818

1919

2020
@frozen
2121
class GroupMetadata:
2222
attributes: Dict[str, Any] = field(factory=dict)
23-
zarr_format: Literal[2, 3] = 3 # field(default=3, validator=validators.in_([2, 3]))
24-
node_type: Literal["group"] = field(default="group", init=False)
23+
zarr_format: Literal[2, 3] = 3
24+
node_type: Literal["group"] = field(default="group", init=True)
2525

2626
def to_bytes(self) -> Dict[str, bytes]:
2727
if self.zarr_format == 3:
@@ -52,7 +52,7 @@ async def create(
5252
*,
5353
attributes: Optional[Dict[str, Any]] = None,
5454
exists_ok: bool = False,
55-
zarr_format: Literal[2, 3] = 3, # field(default=3, validator=validators.in_([2, 3])),
55+
zarr_format: Literal[2, 3] = 3,
5656
runtime_configuration: RuntimeConfiguration = RuntimeConfiguration(),
5757
) -> AsyncGroup:
5858
store_path = make_store_path(store)
@@ -305,13 +305,14 @@ def create(
305305
exists_ok: bool = False,
306306
runtime_configuration: RuntimeConfiguration = RuntimeConfiguration(),
307307
) -> Group:
308-
obj = cls._sync(
308+
obj = sync(
309309
AsyncGroup.create(
310310
store,
311311
attributes=attributes,
312312
exists_ok=exists_ok,
313313
runtime_configuration=runtime_configuration,
314-
)
314+
),
315+
loop=runtime_configuration.asyncio_loop,
315316
)
316317

317318
return cls(obj)
@@ -322,7 +323,9 @@ def open(
322323
store: StoreLike,
323324
runtime_configuration: RuntimeConfiguration = RuntimeConfiguration(),
324325
) -> Group:
325-
obj = cls._sync(AsyncGroup.open(store, runtime_configuration))
326+
obj = sync(
327+
AsyncGroup.open(store, runtime_configuration), loop=runtime_configuration.asyncio_loop
328+
)
326329
return cls(obj)
327330

328331
def __getitem__(self, path: str) -> Union[Array, Group]:

tests/test_group_v3.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,14 @@ def test_group(store_path) -> None:
5454
# and the attrs were modified in the store
5555
bar3 = foo["bar"]
5656
assert dict(bar3.attrs) == {"baz": "qux", "name": "bar"}
57+
58+
59+
def test_group_sync_constructor(store_path) -> None:
60+
61+
group = Group.create(
62+
store=store_path,
63+
attributes={"title": "test 123"},
64+
runtime_configuration=RuntimeConfiguration(),
65+
)
66+
67+
assert group._async_group.metadata.attributes["title"] == "test 123"

0 commit comments

Comments
 (0)