diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 944cf73c..a1c8f2bf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/README.md b/README.md index 93f6dd03..9300ccc1 100644 --- a/README.md +++ b/README.md @@ -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"}) ``` @@ -68,8 +69,8 @@ zarr.config.set({ "chunk_concurrent_minimum": 4, "file_handle_cache_size": 0, "direct_io": False, - "strict": False - } + "strict": False, + }, }) ``` diff --git a/src/lib.rs b/src/lib.rs index 3ce7eb2e..9ef05f2d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, pub(crate) codec_options: CodecOptions, @@ -257,17 +257,15 @@ impl CodecPipelineImpl { DataType::from_metadata(&metadata_v3.data_type).map_py_err::()?; 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::()?; @@ -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::()?; - m.add_class::()?; - 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); diff --git a/src/store.rs b/src/store.rs index 335c77bd..0176fa85 100644 --- a/src/store.rs +++ b/src/store.rs @@ -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) => (), diff --git a/src/store/filesystem.rs b/src/store/filesystem.rs index 0eb59212..37dd8c1c 100644 --- a/src/store/filesystem.rs +++ b/src/store/filesystem.rs @@ -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); } diff --git a/tests/conftest.py b/tests/conftest.py index 33cb1295..6451a656 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) ) diff --git a/tests/pipeline/conftest.py b/tests/pipeline/conftest.py index 8afbe77f..4259ac8e 100644 --- a/tests/pipeline/conftest.py +++ b/tests/pipeline/conftest.py @@ -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 diff --git a/tests/pipeline/test_pipeline.py b/tests/pipeline/test_pipeline.py index b2f0c135..805704d5 100644 --- a/tests/pipeline/test_pipeline.py +++ b/tests/pipeline/test_pipeline.py @@ -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( @@ -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) diff --git a/tests/pipeline/test_roundtrip.py b/tests/pipeline/test_roundtrip.py index db4cb4e6..a0a7ed03 100644 --- a/tests/pipeline/test_roundtrip.py +++ b/tests/pipeline/test_roundtrip.py @@ -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"}) diff --git a/tests/test_zarrs_http.py b/tests/test_zarrs_http.py index 661f8516..45b08d76 100644 --- a/tests/test_zarrs_http.py +++ b/tests/test_zarrs_http.py @@ -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"