Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 4, 2024
1 parent 57a3592 commit 7dcfab4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/anndata/_io/specs/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,14 @@ def write_hdf5_scalar(
):
# Can’t compress scalars, error is thrown
dataset_kwargs = dict(dataset_kwargs)
for arg in ("compression", "compression_opts", "chunks", "shuffle", "fletcher32", "scaleoffset"):
for arg in (
"compression",
"compression_opts",
"chunks",
"shuffle",
"fletcher32",
"scaleoffset",
):
dataset_kwargs.pop(arg, None)
f.create_dataset(key, data=np.array(value), **dataset_kwargs)

Expand Down
13 changes: 10 additions & 3 deletions src/anndata/_io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from collections.abc import Callable, Mapping
from typing import Literal

from .specs.registry import Writer
from .._types import StorageType, _WriteInternal, ContravariantRWAble
from .._types import ContravariantRWAble, StorageType, _WriteInternal
from ..compat import H5Group, ZarrGroup
from .specs.registry import Writer

Storage = StorageType | BaseCompressedSparseDataset

Expand Down Expand Up @@ -294,7 +294,14 @@ def zero_dim_array_as_scalar(func: _WriteInternal):
"""

@wraps(func, assigned=WRAPPER_ASSIGNMENTS + ("__defaults__", "__kwdefaults__"))
def func_wrapper(f: StorageType, k: str, elem: ContravariantRWAble, *, _writer: Writer, dataset_kwargs: Mapping[str, Any]):
def func_wrapper(
f: StorageType,
k: str,
elem: ContravariantRWAble,
*,
_writer: Writer,
dataset_kwargs: Mapping[str, Any],
):
if elem.shape == ():
_writer.write_elem(f, k, elem[()], dataset_kwargs=dataset_kwargs)
else:
Expand Down
6 changes: 5 additions & 1 deletion tests/test_io_elementwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def test_io_spec(store, value, encoding_type):
assert_equal(value, from_disk)
assert get_spec(store[key]) == _REGISTRY.get_spec(value)


@pytest.mark.parametrize(
("value", "encoding_type"),
[
Expand All @@ -219,13 +220,16 @@ def test_io_spec(store, value, encoding_type):
)
def test_io_spec_compressed_scalars(store: G, value: np.ndarray, encoding_type: str):
key = f"key_for_{encoding_type}"
write_elem(store, key, value, dataset_kwargs={"compression": "gzip", "compression_opts": 5})
write_elem(
store, key, value, dataset_kwargs={"compression": "gzip", "compression_opts": 5}
)

assert encoding_type == _read_attr(store[key].attrs, "encoding-type")

from_disk = read_elem(store[key])
assert_equal(value, from_disk)


# Can't instantiate cupy types at the top level, so converting them within the test
@pytest.mark.gpu
@pytest.mark.parametrize(
Expand Down

0 comments on commit 7dcfab4

Please sign in to comment.