Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anndata initializer does not verify indices match on layers #1769

Open
3 tasks done
amcpherson opened this issue Nov 16, 2024 · 2 comments
Open
3 tasks done

anndata initializer does not verify indices match on layers #1769

amcpherson opened this issue Nov 16, 2024 · 2 comments

Comments

@amcpherson
Copy link

Please make sure these conditions are met

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of anndata.
  • (optional) I have confirmed this bug exists on the master branch of anndata.

Report

The AnnData Initializer verifies index and columns of the input X match var and obs, but does not do the same for layers resulting in possible bugs especially when initializing with layers but no X.

Code:

import numpy as np
import pandas as pd
import anndata as ad

var = pd.DataFrame(index=["gene1", "gene2"])
different_indices = ["gene2", "gene1"]
layer_data = pd.DataFrame(np.array([[5, 6], [7, 8]]), columns=different_indices)
layers = {"layer1": layer_data}
adata = ad.AnnData(obs=obs, var=var, layers=layers)

Versions

-----
anndata             0.11.1.dev10+gaf6480e
session_info        1.0.0
-----
cython_runtime      NA
dateutil            2.9.0.post0
exceptiongroup      1.2.2
h5py                3.12.1
natsort             8.4.0
numpy               2.0.2
packaging           24.2
pandas              2.2.3
pytz                2024.2
scipy               1.14.1
six                 1.16.0
zoneinfo            NA
-----
Python 3.10.15 | packaged by conda-forge | (main, Oct 16 2024, 01:24:20) [Clang 17.0.6 ]
macOS-14.6.1-arm64-arm-64bit
-----
Session information updated at 2024-11-15 21:08
@amcpherson
Copy link
Author

Happy to try to fix and submit a PR given some advice on how to proceed

@ilan-gold
Copy link
Contributor

@amcpherson I think this should be ok, although I am not sure the correct intention for layers. The docs only say "Dictionary-like object with values of the same dimensions as X." At this point people might actually be relying on the behavior you describe since the docs only specify that the dimensions be the same. I would need a stronger counter-example or @flying-sheep should weigh in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants