Skip to content

concat errors with one dimensional arrays in obsm  #652

@ivirshup

Description

@ivirshup

Seen in comment by @Hrovatin in #501 (comment)_

import anndata as ad, numpy as np

foo = ad.AnnData(np.ones((5, 20), obsm={"1d-array": np.ones(5)})

ad.concat([foo, foo])
Traceback
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/var/folders/bd/43q20k0n6z15tdfzxvd22r7c0000gn/T/ipykernel_14520/2434769132.py in <module>
----> 1 ad.concat([a, a])

~/github/anndata/anndata/_core/merge.py in concat(adatas, axis, join, merge, uns_merge, label, keys, index_unique, fill_value, pairwise)
    848             [a.layers for a in adatas], axis=axis, reindexers=reindexers
    849         )
--> 850         concat_mapping = inner_concat_aligned_mapping(
    851             [getattr(a, f"{dim}m") for a in adatas], index=concat_indices
    852         )

~/github/anndata/anndata/_core/merge.py in inner_concat_aligned_mapping(mappings, reindexers, index, axis)
    455         els = [m[k] for m in mappings]
    456         if reindexers is None:
--> 457             cur_reindexers = gen_inner_reindexers(els, new_index=index, axis=axis)
    458         else:
    459             cur_reindexers = reindexers

~/github/anndata/anndata/_core/merge.py in gen_inner_reindexers(els, new_index, axis)
    476         reindexers = [Reindexer(df_indices(el), common_ind) for el in els]
    477     else:
--> 478         min_ind = min(el.shape[alt_axis] for el in els)
    479         reindexers = [
    480             gen_reindexer(pd.RangeIndex(min_ind), pd.RangeIndex(el.shape[alt_axis]))

~/github/anndata/anndata/_core/merge.py in <genexpr>(.0)
    476         reindexers = [Reindexer(df_indices(el), common_ind) for el in els]
    477     else:
--> 478         min_ind = min(el.shape[alt_axis] for el in els)
    479         reindexers = [
    480             gen_reindexer(pd.RangeIndex(min_ind), pd.RangeIndex(el.shape[alt_axis]))

IndexError: tuple index out of range

Off the top of my head, I can't think of a reason this working would be inconsistent with the anndata model. Generally I would expect people to put 1d arrays in obs though.

Might have implications for the concatenation of awkward arrays (#647)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions