Repository navigation
Conversation
The zero-shape branch of _apply_to_dask_array (el.shape[axis] == 0) always returned da.broadcast_to(fill_value, shape), a plain dense array, regardless of el's dtype/format. The sibling _apply_to_sparse (used for plain, non-dask sparse inputs) handles the identical scenario -- reindex-and-pad a zero-length axis during an outer join -- by explicitly reconstructing a sparse result (csr_cls(shape) when fill_value is 0, or a sparse-wrapped broadcast otherwise). The sparse-aware "fast path" earlier in this same method only covers the case where the reindexed axis is the array's unchunked minor axis; a CSR-backed dask array reindexed along its major (chunked) axis with a zero-length input -- e.g. one input of an outer-join anndata.concat that contributes 0 obs along the concatenation axis -- falls through to the generic zero-shape branch and gets silently densified. Verified against the real anndata/dask/scipy machinery (not just a standalone reimplementation): copied the current _apply_to_dask_array body verbatim and ran it against a real Reindexer with a 0-row CSR-backed dask array reindexed along its major axis during an outer join -- confirmed the pre-fix code returns a dense numpy-backed dask array (result._meta is a numpy.ndarray), while the sibling _apply_to_sparse on the equivalent plain-sparse input returns a real scipy.sparse.csr_matrix for the identical shape and content. Also verified: a nonzero fill_value on the same zero-axis sparse case still produces the correct filled values, and a normal (non-zero-axis) dense reindex is unaffected by this change. Fix: when the zero-length-axis input's dask _meta is sparse (CSArray/CSMatrix), materialize it (cheap -- it's empty along this axis regardless of the other axis's size) and delegate to the already- correct _apply_to_sparse zero-shape branch, then wrap the result back into a dask array via da.from_array. Falls through to the existing da.broadcast_to path unchanged for dense inputs. Signed-off-by: Siddhardha Nanda <99672439+SID-6921@users.noreply.github.com>
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2737 +/- ##
==========================================
- Coverage 87.66% 85.74% -1.93%
==========================================
Files 49 49
Lines 7729 8240 +511
==========================================
+ Hits 6776 7065 +289
- Misses 953 1175 +222
|
|
Checked all 4 failing checks, none require a code change from this PR:
The real test suite (hatch-test across the matrix, including dask_distributed and array_api variants) and pre-commit are passing where completed. Happy to address anything specific if I'm missing something. |
|
The 2 real test failures ( The two Triage checks (PR title/milestone/labels, GPU test approval) and the |
|
The two red test jobs here ( |
What
The zero-shape branch of
Reindexer._apply_to_dask_array(el.shape[axis] == 0) always returnedda.broadcast_to(fill_value, shape), a plain dense array, regardless ofel's dtype/format. The sibling_apply_to_sparse(used for plain, non-dask sparse inputs) handles the identical scenario — reindex-and-pad a zero-length axis during an outer join — by explicitly reconstructing a sparse result (csr_cls(shape)whenfill_valueis 0, or a sparse-wrapped broadcast otherwise). The sparse-aware "fast path" earlier in this same method only covers the case where the reindexed axis is the array's unchunked minor axis; a CSR-backed dask array reindexed along its major (chunked) axis with a zero-length input — e.g. one input of an outer-joinanndata.concatthat contributes 0 obs along the concatenation axis — falls through to the generic zero-shape branch and gets silently densified.Verification
Verified against the real anndata/dask/scipy machinery, not just a standalone reimplementation: copied the current
_apply_to_dask_arraybody verbatim and ran it against a realReindexerwith a 0-row CSR-backed dask array reindexed along its major axis during an outer join — confirmed the pre-fix code returns a dense numpy-backed dask array (result._metais anumpy.ndarray), while the sibling_apply_to_sparseon the equivalent plain-sparse input returns a realscipy.sparse.csr_matrixfor the identical shape and content. Also verified a nonzerofill_valueon the same zero-axis sparse case still produces the correct filled values, and a normal (non-zero-axis) dense reindex is unaffected by this change.Fix
When the zero-length-axis input's dask
_metais sparse (CSArray/CSMatrix), materialize it (cheap — it's empty along this axis regardless of the other axis's size) and delegate to the already-correct_apply_to_sparsezero-shape branch, then wrap the result back into a dask array viada.from_array. Falls through to the existingda.broadcast_topath unchanged for dense inputs.