Use correct shape for obsm/varm layers in anndata export #216
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This addresses a bug in the
ExperimentAxisQuery
anndata exporter that is specific toobsm
/varm
arrays.Details
Currently, the number of columns needed for the resulting numpy array is taken from the
SparseNDArray
's shape property, which provides the maximum capacity of the underlying TileDB array, rather than the occupied capacity. This results in the exporter allocating a far larger numpyndarray
than necessary when obsm/varm layers are included in the output.This issue is specific to
obsm
/varm
arrays because, unlikeX
/obsp
/varp
, and as described here, their second dimension doesn't map to theobs
orvar
axis and can include an arbitrary number of columns.Solution
With this PR the correct number of columns needed for the resulting numpy array is computed using the number of unique values present in the COO-formatted arrow table's
"soma_dim_1"
column, which is already in-memory and doesn't require any additional TileDB queries.This solution is a temporary workaround, as
SparseNDArray.shape
's behavior will change in an upcoming release of TileDB-SOMA (see here for status).Note: The TileDB-SOMA
SparseNDArray
class does provide aused_shape
property that returns the occupied capacity of the underlying TileDB array that could be used, however, this is specific to the TileDB implementation and is not part of the SOMA API specification.[sc-51048].