From a07e1f0a6057f0b126a932f5ecdc6a4955035ab0 Mon Sep 17 00:00:00 2001 From: ilan-gold Date: Wed, 20 Nov 2024 15:09:16 +0100 Subject: [PATCH] (fix): python debugger dask h5 meta array --- src/anndata/_io/specs/lazy_methods.py | 6 ++++-- tests/test_io_elementwise.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/anndata/_io/specs/lazy_methods.py b/src/anndata/_io/specs/lazy_methods.py index a34f627e7..0b35c34da 100644 --- a/src/anndata/_io/specs/lazy_methods.py +++ b/src/anndata/_io/specs/lazy_methods.py @@ -150,7 +150,7 @@ def read_h5_array( c if c not in {None, -1} else s for c, s in zip(chunks, shape, strict=True) ) if chunks is not None - else (_DEFAULT_STRIDE,) * len(shape) + else tuple(min(_DEFAULT_STRIDE, s) for s in shape) ) chunk_layout = tuple( @@ -159,7 +159,9 @@ def read_h5_array( ) make_chunk = partial(make_dask_chunk, path, elem_name) - return da.map_blocks(make_chunk, dtype=dtype, chunks=chunk_layout) + return da.map_blocks( + make_chunk, dtype=dtype, chunks=chunk_layout, meta=np.array([]) + ) @_LAZY_REGISTRY.register_read(ZarrArray, IOSpec("array", "0.2.0")) diff --git a/tests/test_io_elementwise.py b/tests/test_io_elementwise.py index 3ca5324b8..5647bcfeb 100644 --- a/tests/test_io_elementwise.py +++ b/tests/test_io_elementwise.py @@ -73,8 +73,10 @@ def sparse_format(request): return request.param -def create_dense_store(store, n_dims: int = 2): - X = np.random.randn(*[SIZE * (i + 1) for i in range(n_dims)]) +def create_dense_store( + store: str, n_dims: int = 2, shape=(SIZE, SIZE * 2) +) -> H5Group | ZarrGroup: + X = np.random.randn(*shape) write_elem(store, "X", X) return store @@ -317,6 +319,14 @@ def test_read_lazy_h5_cluster(sparse_format, tmp_path): assert_equal(X_from_disk, X_dask_from_disk) +def test_undersized_shape_to_default(store): + shape = (3000, 50) + arr_store = create_dense_store(store, shape=shape) + X_dask_from_disk = read_elem_as_dask(arr_store["X"]) + assert (c < s for c, s in zip(X_dask_from_disk.chunksize, shape)) + assert X_dask_from_disk.shape == shape + + @pytest.mark.parametrize( ("arr_type", "chunks", "expected_chunksize"), [