From a96d0d0c2c2016438e74dc69b4b228a9c406afe1 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Tue, 23 Jun 2026 17:24:33 -0400 Subject: [PATCH 1/3] feat: Automatically store metadata when creating an array from ArrayBuilder --- src/array/builder.rs | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/array/builder.rs b/src/array/builder.rs index 467877c..655c5ea 100644 --- a/src/array/builder.rs +++ b/src/array/builder.rs @@ -1,5 +1,6 @@ use pyo3::exceptions::PyTypeError; use pyo3::prelude::*; +use pyo3_async_runtimes::tokio::future_into_py; use zarrs::array::ArrayBuilder; use crate::array::util::PyArrayShape; @@ -7,6 +8,7 @@ use crate::array::{PyArray, PyAsyncArray, PyChunkGrid, PyChunkKeyEncoding}; use crate::codec::{PyArrayToArrayCodec, PyArrayToBytesCodec, PyBytesToBytesCodec}; use crate::dtype::PyDataType; use crate::error::ZarristaResult; +use crate::exceptions::ZarristaError; use crate::fill_value::PyFillValue; use crate::metadata::{PyArrayMetadataV3, PyAttributes}; use crate::storage::{PyAsyncStorage, PySyncStorage}; @@ -77,15 +79,29 @@ impl PyArrayBuilder { } fn create(&self, store: PySyncStorage, path: &str) -> ZarristaResult { - // TODO: should this additionally store the metadata? Or make the user call store_metadata - // on the result themselves? - Ok(self.0.build_arc(store.into_inner(), path)?.into()) - } - - fn create_async(&self, store: PyAsyncStorage, path: &str) -> ZarristaResult { - // TODO: should this additionally store the metadata? Or make the user call store_metadata - // on the result themselves? - Ok(self.0.build_arc(store.into_inner(), path)?.into()) + let array = self.0.build_arc(store.into_inner(), path)?; + array.store_metadata()?; + Ok(array.into()) + } + + fn create_async<'py>( + &self, + py: Python<'py>, + store: PyAsyncStorage, + path: &str, + ) -> PyResult> { + let array = self + .0 + .build_arc(store.into_inner(), path) + .map_err(ZarristaError::from)?; + + future_into_py(py, async move { + array + .async_store_metadata() + .await + .map_err(ZarristaError::from)?; + Ok(()) + }) } fn create_metadata(&self) -> ZarristaResult { From 1ccc391559c92914e785496dc5acd8280434e294 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Tue, 23 Jun 2026 17:29:01 -0400 Subject: [PATCH 2/3] fix compile --- src/array/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array/builder.rs b/src/array/builder.rs index 655c5ea..6838e8f 100644 --- a/src/array/builder.rs +++ b/src/array/builder.rs @@ -7,8 +7,8 @@ use crate::array::util::PyArrayShape; use crate::array::{PyArray, PyAsyncArray, PyChunkGrid, PyChunkKeyEncoding}; use crate::codec::{PyArrayToArrayCodec, PyArrayToBytesCodec, PyBytesToBytesCodec}; use crate::dtype::PyDataType; +use crate::error::ZarristaError; use crate::error::ZarristaResult; -use crate::exceptions::ZarristaError; use crate::fill_value::PyFillValue; use crate::metadata::{PyArrayMetadataV3, PyAttributes}; use crate::storage::{PyAsyncStorage, PySyncStorage}; From e82793b2b1d1eeaf21506ad2aa7ccee86a975b8c Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Tue, 23 Jun 2026 17:30:33 -0400 Subject: [PATCH 3/3] fix type hint --- python/zarrista/_builder.pyi | 2 +- src/array/builder.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/zarrista/_builder.pyi b/python/zarrista/_builder.pyi index 1721d41..539dd3e 100644 --- a/python/zarrista/_builder.pyi +++ b/python/zarrista/_builder.pyi @@ -79,7 +79,7 @@ class ArrayBuilder: """Return a new builder with the inner (subchunk) shape, enabling sharding.""" def create(self, store: FilesystemStore | MemoryStore, path: str) -> Array: """Build the array in `store` at `path` and return it.""" - def create_async(self, store: AsyncStore, path: str) -> AsyncArray: + async def create_async(self, store: AsyncStore, path: str) -> AsyncArray: """Build the array in an async `store` at `path` and return it.""" def create_metadata(self) -> ArrayMetadataV3: """Build the array's Zarr v3 metadata without touching a store.""" diff --git a/src/array/builder.rs b/src/array/builder.rs index 6838e8f..408d55d 100644 --- a/src/array/builder.rs +++ b/src/array/builder.rs @@ -100,7 +100,7 @@ impl PyArrayBuilder { .async_store_metadata() .await .map_err(ZarristaError::from)?; - Ok(()) + Ok(PyAsyncArray::from(array)) }) }