Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/zarrista/_builder.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
34 changes: 25 additions & 9 deletions src/array/builder.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use pyo3::exceptions::PyTypeError;
use pyo3::prelude::*;
use pyo3_async_runtimes::tokio::future_into_py;
use zarrs::array::ArrayBuilder;

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::fill_value::PyFillValue;
use crate::metadata::{PyArrayMetadataV3, PyAttributes};
Expand Down Expand Up @@ -77,15 +79,29 @@ impl PyArrayBuilder {
}

fn create(&self, store: PySyncStorage, path: &str) -> ZarristaResult<PyArray> {
// 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<PyAsyncArray> {
// 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<Bound<'py, PyAny>> {
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(PyAsyncArray::from(array))
})
}

fn create_metadata(&self) -> ZarristaResult<PyArrayMetadataV3> {
Expand Down
Loading