Skip to content

concat errors with one dimensional arrays in obsm  #652

Closed

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)

Activity

  1. Hrovatin commented on Nov 29, 2021

    @Hrovatin

    Yes, it was mistake from my side to put one-d array (forgot to reshape it). But I got no warning when I made adata and then just by chance figured out what was the reason.

  2. added this to the 0.10.0 milestone on Feb 2, 2023
  3. github-actions commented on Aug 23, 2023

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity.
    Please add a comment if you want to keep the issue open. Thank you for your contributions!

  4. modified the milestones: 0.10.0, 0.11.0 on Sep 5, 2023
  5. self-assigned this
    on Jun 3, 2024
  6. ilan-gold commented on Jun 4, 2024

    @ilan-gold
    Contributor

    @ivirshup @flying-sheep Should this work actually? Or should we start enforcing a multi-dimensional-ness for obsm? https://anndata.readthedocs.io/en/latest/generated/anndata.AnnData.obsm.html#anndata.AnnData.obsm makes it pretty clear that "Stores for each key a two or higher-dimensional" - does this mean that even something with shape [10, 1] should be disallowed?

  7. modified the milestones: 0.11.0, 0.12.0 on Aug 8, 2024
  8. ilan-gold commented on Feb 20, 2025

    @ilan-gold
    Contributor

    Reshape the array

  9. added theissue type on Nov 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions