Skip to content

Commit

Permalink
deps: slim zarr dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamman committed Oct 16, 2024
1 parent 1131253 commit 002b805
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 20 deletions.
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@ repos:
files: src|tests
additional_dependencies:
# Package dependencies
- asciitree
- crc32c
- donfig
- fasteners
- numcodecs
- numpy
- typing_extensions
- universal-pathlib
# Tests
- pytest
# Zarr v2
- types-redis
- repo: https://github.com/scientific-python/cookie
rev: 2024.08.19
hooks:
Expand Down
16 changes: 7 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ maintainers = [
requires-python = ">=3.11"
# If you add a new dependency here, please also add it to .pre-commit-config.yml
dependencies = [
'asciitree',
'numpy>=1.25',
'fasteners',
'numcodecs>=0.10.2',
'fsspec>2024',
'crc32c',
'numcodecs>=0.12',
'typing_extensions',
'donfig',
]
Expand All @@ -52,17 +48,19 @@ license = {text = "MIT License"}
keywords = ["Python", "compressed", "ndimensional-arrays", "zarr"]

[project.optional-dependencies]
remote = [
"fsspec",
]
sharding = [
"crc32c",
]
test = [
"coverage",
"pytest",
"pytest-cov",
"msgpack",
"lmdb",
"s3fs",
"pytest-asyncio",
"moto[s3]",
"flask-cors",
"flask",
"requests",
"mypy",
"hypothesis",
Expand Down
5 changes: 4 additions & 1 deletion src/zarr/codecs/crc32c_.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import numpy as np
import typing_extensions
from crc32c import crc32c

from zarr.abc.codec import BytesBytesCodec
from zarr.core.common import JSON, parse_named_configuration
Expand Down Expand Up @@ -35,6 +34,8 @@ async def _decode_single(
chunk_bytes: Buffer,
chunk_spec: ArraySpec,
) -> Buffer:
from crc32c import crc32c

data = chunk_bytes.as_numpy_array()
crc32_bytes = data[-4:]
inner_bytes = data[:-4]
Expand All @@ -53,6 +54,8 @@ async def _encode_single(
chunk_bytes: Buffer,
chunk_spec: ArraySpec,
) -> Buffer | None:
from crc32c import crc32c

data = chunk_bytes.as_numpy_array()
# Calculate the checksum and "cast" it to a numpy array
checksum = np.array([crc32c(cast(typing_extensions.Buffer, data))], dtype=np.uint32)
Expand Down
4 changes: 2 additions & 2 deletions src/zarr/storage/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from typing import TYPE_CHECKING, Any, Self

import fsspec

from zarr.abc.store import ByteRangeRequest, Store
from zarr.storage.common import _dereference_path

Expand Down Expand Up @@ -130,6 +128,8 @@ def from_url(
-------
RemoteStore
"""
import fsspec

fs, path = fsspec.url_to_fs(url, **storage_options)
return cls(fs=fs, path=path, mode=mode, allowed_exceptions=allowed_exceptions)

Expand Down
2 changes: 2 additions & 0 deletions tests/v3/test_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ async def test_async_array_gpu_prototype() -> None:

@pytest.mark.asyncio
async def test_codecs_use_of_prototype() -> None:
pytest.importorskip("crc32c")
expect = np.zeros((10, 10), dtype="uint16", order="F")
a = await AsyncArray.create(
StorePath(StoreExpectingTestBuffer(mode="w")) / "test_codecs_use_of_prototype",
Expand Down Expand Up @@ -132,6 +133,7 @@ async def test_codecs_use_of_prototype() -> None:
@gpu_test
@pytest.mark.asyncio
async def test_codecs_use_of_gpu_prototype() -> None:
pytest.importorskip("crc32c")
expect = cp.zeros((10, 10), dtype="uint16", order="F")
a = await AsyncArray.create(
StorePath(MemoryStore(mode="w")) / "test_codecs_use_of_gpu_prototype",
Expand Down
4 changes: 4 additions & 0 deletions tests/v3/test_codecs/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ async def test_order(
runtime_read_order: MemoryOrder,
with_sharding: bool,
) -> None:
if with_sharding:
pytest.importorskip("crc32c")
data = np.arange(0, 256, dtype="uint16").reshape((32, 8), order=input_order)
path = "order"
spath = StorePath(store, path=path)
Expand Down Expand Up @@ -129,6 +131,8 @@ def test_order_implicit(
runtime_read_order: MemoryOrder,
with_sharding: bool,
) -> None:
if with_sharding:
pytest.importorskip("crc32c")
data = np.arange(0, 256, dtype="uint16").reshape((16, 16), order=input_order)
path = "order_implicit"
spath = StorePath(store, path)
Expand Down
2 changes: 2 additions & 0 deletions tests/v3/test_codecs/test_sharding.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from ..conftest import ArrayRequest
from .test_codecs import _AsyncArrayProxy, order_from_dim

pytest.importorskip("crc32c")


@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"])
@pytest.mark.parametrize("index_location", ["start", "end"])
Expand Down
2 changes: 2 additions & 0 deletions tests/v3/test_codecs/test_transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ async def test_transpose(
runtime_read_order: MemoryOrder,
with_sharding: bool,
) -> None:
if with_sharding:
pytest.importorskip("crc32c")
data = np.arange(0, 256, dtype="uint16").reshape((1, 32, 8), order=input_order)
spath = StorePath(store, path="transpose")
codecs_: list[Codec] = (
Expand Down
3 changes: 3 additions & 0 deletions tests/v3/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ def test_config_buffer_implementation() -> None:
arr[:] = np.arange(100)
assert np.array_equal(arr[:], data)


def test_config_sharding_implementation() -> None:
pytest.importorskip("crc32c")
data2d = np.arange(1000).reshape(100, 10)
arr_sharding = zeros(
shape=(100, 10),
Expand Down
2 changes: 1 addition & 1 deletion tests/v3/test_store/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def test_make_store_path(tmpdir: str) -> None:


async def test_make_store_path_fsspec(monkeypatch) -> None:
import fsspec.implementations.memory
fsspec = pytest.importorskip("fsspec")

monkeypatch.setattr(fsspec.implementations.memory.MemoryFileSystem, "async_impl", True)
store_path = await make_store_path("memory://")
Expand Down
6 changes: 3 additions & 3 deletions tests/v3/test_store/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import os
from typing import TYPE_CHECKING

import fsspec
import pytest
from botocore.session import Session
from upath import UPath

import zarr.api.asynchronous
from zarr.core.buffer import Buffer, cpu, default_buffer_prototype
Expand All @@ -21,6 +19,7 @@
import botocore.client


fsspec = pytest.importorskip("fsspec")
s3fs = pytest.importorskip("s3fs")
requests = pytest.importorskip("requests")
moto_server = pytest.importorskip("moto.moto_server.threaded_moto_server")
Expand Down Expand Up @@ -183,7 +182,8 @@ async def test_remote_store_from_uri(
assert dict(group.attrs) == {"key": "value-3"}

def test_from_upath(self) -> None:
path = UPath(f"s3://{test_bucket_name}", endpoint_url=endpoint_url, anon=False)
upath = pytest.importorskip("upath")
path = upath.UPath(f"s3://{test_bucket_name}", endpoint_url=endpoint_url, anon=False)
result = RemoteStore.from_upath(path)
assert result.fs.endpoint_url == endpoint_url

Expand Down

0 comments on commit 002b805

Please sign in to comment.