Skip to content

Commit

Permalink
(fix): python debugger dask h5 meta array
Browse files Browse the repository at this point in the history
  • Loading branch information
ilan-gold committed Nov 20, 2024
1 parent 2602e5b commit a07e1f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/anndata/_io/specs/lazy_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"))
Expand Down
14 changes: 12 additions & 2 deletions tests/test_io_elementwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
[
Expand Down

0 comments on commit a07e1f0

Please sign in to comment.