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
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ repos:
language: system
pass_filenames: false
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.16.4
rev: v0.16.5
hooks:
- id: ruff
args: ["--fix"]
- id: ruff-format
args: ["--preview"]
# The following can be removed once PLR0917 is out of preview
- name: ruff preview rules
id: ruff
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ To use the project, simply install our package `zarrs` from PyPI (which depends

```python
import zarr

zarr.config.set({"codec_pipeline.path": "zarrs.ZarrsCodecPipeline"})
```

Expand Down Expand Up @@ -68,8 +69,8 @@ zarr.config.set({
"chunk_concurrent_minimum": 4,
"file_handle_cache_size": 0,
"direct_io": False,
"strict": False
}
"strict": False,
},
})
```

Expand Down
35 changes: 18 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate::utils::{PyCodecErrExt, PyErrExt as _};
// TODO: Use a OnceLock for store with get_or_try_init when stabilised?
#[gen_stub_pyclass]
#[pyclass]
pub struct CodecPipelineImpl {
pub(crate) struct CodecPipelineImpl {
pub(crate) store: ReadableWritableListableStorage,
pub(crate) codec_chain: Arc<CodecChain>,
pub(crate) codec_options: CodecOptions,
Expand Down Expand Up @@ -257,17 +257,15 @@ impl CodecPipelineImpl {
DataType::from_metadata(&metadata_v3.data_type).map_py_err::<PyTypeError>()?;
let fill_value = data_type
.fill_value(&metadata_v3.fill_value, ZarrVersion::V3)
.or_else(|_| {
Err(match &metadata {
ArrayMetadata::V2(metadata) => format!(
"incompatible fill value metadata: dtype={}, fill_value={}",
metadata.dtype, metadata.fill_value
),
ArrayMetadata::V3(metadata) => format!(
"incompatible fill value metadata: data_type={}, fill_value={}",
metadata.data_type, metadata.fill_value
),
})
.map_err(|_| match &metadata {
ArrayMetadata::V2(metadata) => format!(
"incompatible fill value metadata: dtype={}, fill_value={}",
metadata.dtype, metadata.fill_value
),
ArrayMetadata::V3(metadata) => format!(
"incompatible fill value metadata: data_type={}, fill_value={}",
metadata.data_type, metadata.fill_value
),
})
.map_py_err::<PyTypeError>()?;

Expand Down Expand Up @@ -469,11 +467,14 @@ impl CodecPipelineImpl {

/// A Python module implemented in Rust.
#[pymodule]
fn _internal(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add("__version__", env!("CARGO_PKG_VERSION"))?;
m.add_class::<CodecPipelineImpl>()?;
m.add_class::<chunk_item::ChunkItem>()?;
Ok(())
pub mod _internal {
#[pymodule_export]
#[allow(non_upper_case_globals)]
const __version__: &str = env!("CARGO_PKG_VERSION");
#[pymodule_export]
use super::CodecPipelineImpl;
#[pymodule_export]
use super::chunk_item::ChunkItem;
}

define_stub_info_gatherer!(stub_info);
2 changes: 1 addition & 1 deletion src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<'py> FromPyObject<'_, 'py> for StoreConfig {
}

impl StoreConfig {
pub fn direct_io(&mut self, flag: bool) -> () {
pub fn direct_io(&mut self, flag: bool) {
match self {
StoreConfig::Filesystem(config) => config.direct_io(flag),
StoreConfig::Http(_config) => (),
Expand Down
2 changes: 1 addition & 1 deletion src/store/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl FilesystemStoreConfig {
}
}

pub fn direct_io(&mut self, flag: bool) -> () {
pub fn direct_io(&mut self, flag: bool) {
self.opts.direct_io(flag);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ async def store(request: pytest.FixtureRequest, tmp_path: Path) -> Store:
def array_fixture(request: pytest.FixtureRequest) -> npt.NDArray[Any]:
array_request: ArrayRequest = request.param
return (
np.arange(np.prod(array_request.shape))
np
.arange(np.prod(array_request.shape))
.reshape(array_request.shape, order=array_request.order)
.astype(array_request.dtype)
)
Expand Down
14 changes: 6 additions & 8 deletions tests/pipeline/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,12 @@ def roundtrip_params() -> Generator[ParameterSet]:
if sum(isinstance(i, EllipsisType) for i in index) > 1:
continue
for indexing_method_param in indexing_method_params:
id = "-".join(
[
str(indexing_method_param.id),
f"{dimensionality}d",
*(str(index_param.id) for index_param in index_param_prod),
f"v{format}",
]
)
id = "-".join([
str(indexing_method_param.id),
f"{dimensionality}d",
*(str(index_param.id) for index_param in index_param_prod),
f"v{format}",
])
indexing_method = indexing_method_param.values[0]
yield pytest.param(
(format, dimensionality, index, indexing_method), id=id
Expand Down
30 changes: 12 additions & 18 deletions tests/pipeline/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,15 @@ def test_pipeline_used(

@pytest.fixture
def use_zarrs_direct_io() -> Generator[None]:
zarr.config.set(
{
"codec_pipeline.path": "zarrs.ZarrsCodecPipeline",
"codec_pipeline.direct_io": True,
}
)
zarr.config.set({
"codec_pipeline.path": "zarrs.ZarrsCodecPipeline",
"codec_pipeline.direct_io": True,
})
yield
zarr.config.set(
{
"codec_pipeline.path": "zarrs.ZarrsCodecPipeline",
"codec_pipeline.direct_io": False,
}
)
zarr.config.set({
"codec_pipeline.path": "zarrs.ZarrsCodecPipeline",
"codec_pipeline.direct_io": False,
})


@pytest.mark.skipif(
Expand Down Expand Up @@ -154,12 +150,10 @@ def test_file_handle_cache(tmp_path: Path, cache_size: int) -> None:
path = tmp_path / "foo.zarr"
ground_truth_arr = _sharded_array(path)

with zarr.config.set(
{
"codec_pipeline.path": "zarrs.ZarrsCodecPipeline",
"codec_pipeline.file_handle_cache_size": cache_size,
}
):
with zarr.config.set({
"codec_pipeline.path": "zarrs.ZarrsCodecPipeline",
"codec_pipeline.file_handle_cache_size": cache_size,
}):
before = _open_fds()
z = zarr.open_array(path, mode="r")
np.testing.assert_array_equal(z[...], ground_truth_arr)
Expand Down
6 changes: 3 additions & 3 deletions tests/pipeline/test_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def indexing_method(roundtrip: tuple[Literal[2, 3], int, Index, Callable]) -> Ca

@contextmanager
def use_zarr_default_codec_reader() -> Generator[None]:
zarr.config.set(
{"codec_pipeline.path": "zarr.core.codec_pipeline.BatchedCodecPipeline"}
)
zarr.config.set({
"codec_pipeline.path": "zarr.core.codec_pipeline.BatchedCodecPipeline"
})
yield
zarr.config.set({"codec_pipeline.path": "zarrs.ZarrsCodecPipeline"})

Expand Down
22 changes: 10 additions & 12 deletions tests/test_zarrs_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
import zarr
from zarr.storage import FsspecStore

ARR_REF = np.array(
[
[np.nan, np.nan, np.nan, np.nan, 0.1, 0.1, -0.6, 0.1],
[np.nan, np.nan, np.nan, np.nan, 0.1, 0.1, -1.6, 0.1],
[np.nan, np.nan, np.nan, np.nan, 0.1, 0.1, -2.6, 0.1],
[np.nan, np.nan, np.nan, np.nan, -3.4, -3.5, -3.6, 0.1],
[1.0, 1.0, 1.0, -4.3, -4.4, -4.5, -4.6, 1.1],
[1.0, 1.0, 1.0, -5.3, -5.4, -5.5, -5.6, 1.1],
[1.0, 1.0, 1.0, 1.0, 1.1, 1.1, -6.6, 1.1],
[1.0, 1.0, 1.0, 1.0, -7.4, -7.5, -7.6, -7.7],
]
)
ARR_REF = np.array([
[np.nan, np.nan, np.nan, np.nan, 0.1, 0.1, -0.6, 0.1],
[np.nan, np.nan, np.nan, np.nan, 0.1, 0.1, -1.6, 0.1],
[np.nan, np.nan, np.nan, np.nan, 0.1, 0.1, -2.6, 0.1],
[np.nan, np.nan, np.nan, np.nan, -3.4, -3.5, -3.6, 0.1],
[1.0, 1.0, 1.0, -4.3, -4.4, -4.5, -4.6, 1.1],
[1.0, 1.0, 1.0, -5.3, -5.4, -5.5, -5.6, 1.1],
[1.0, 1.0, 1.0, 1.0, 1.1, 1.1, -6.6, 1.1],
[1.0, 1.0, 1.0, 1.0, -7.4, -7.5, -7.6, -7.7],
])

URL = "https://raw.githubusercontent.com/zarrs/zarrs/main/zarrs/tests/data/array_write_read.zarr/group/array"

Expand Down
Loading