Skip to content

Commit

Permalink
(fix): handling of off axis size when no-dask array
Browse files Browse the repository at this point in the history
  • Loading branch information
ilan-gold committed Jan 28, 2025
1 parent c9253a9 commit 8b2e208
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/anndata/_core/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,12 +943,11 @@ def missing_element(
els: list[SpArray | sparse.csr_matrix | sparse.csc_matrix | np.ndarray | DaskArray],
axis: Literal[0, 1] = 0,
fill_value: Any | None = None,
off_axis_size: int | None = None,
off_axis_size: int = 0,
) -> np.ndarray | DaskArray:
"""Generates value to use when there is a missing element."""
should_return_dask = any(isinstance(el, DaskArray) for el in els)
# 0 sized array for in-memory prevents allocating unnecessary memory while preserving broadcasting.
off_axis_size = 0 if not should_return_dask else off_axis_size
shape = (n, off_axis_size) if axis == 0 else (off_axis_size, n)
if should_return_dask:
import dask.array as da
Expand All @@ -972,6 +971,13 @@ def outer_concat_aligned_mapping(
else:
cur_reindexers = reindexers

# Dask needs to create a full array and can't do the size-0 trick
off_axis_size = 0
if any(isinstance(e, DaskArray) for e in els):
if not isinstance(cur_reindexers[0], Reindexer):
msg = "Cannot re-index a dask array without a Reindexer"
raise ValueError(msg)

Check warning on line 979 in src/anndata/_core/merge.py

View check run for this annotation

Codecov / codecov/patch

src/anndata/_core/merge.py#L978-L979

Added lines #L978 - L979 were not covered by tests
off_axis_size = cur_reindexers[0].get_new_idx_from_old_idx().shape[0]
# Handling of missing values here is hacky for dataframes
# We should probably just handle missing elements for all types
result[k] = concat_arrays(
Expand All @@ -983,7 +989,7 @@ def outer_concat_aligned_mapping(
axis=axis,
els=els,
fill_value=fill_value,
off_axis_size=cur_reindexers[0].get_new_idx_from_old_idx().shape[0],
off_axis_size=off_axis_size,
)
for el, n in zip(els, ns)
],
Expand Down

0 comments on commit 8b2e208

Please sign in to comment.