AnnData Repo Skill
Use this repo skill when a task involves anndata, AnnData, annotated data matrices, .h5ad, .zarr, backed mode, lazy reads, anndata.concat, AnnCollection, anndata.acc, or AnnData extension namespaces. AnnData is a Python package for annotated data matrices with aligned observations, variables, multidimensional annotations, pairwise arrays, layers, unstructured metadata, and native HDF5/Zarr storage.
First Checks
- Install AnnData with
pip install anndataorconda install -c conda-forge anndatawhen the project does not already provide it. - For lazy reads or remote Zarr workflows, install the package extra that provides
xarray,dask,requests, andaiohttp:pip install "anndata[lazy]". - Prefer public imports such as
import anndata as adandfrom anndata import AnnData; avoid leading-underscore internals unless the task is explicitly repository maintenance. - Confirm importability before deeper work:
python - <<'PY'
import anndata as ad
from anndata import AnnData
print(ad.__name__, AnnData)
PY
- Run
scripts/smoke_anndata_core.pyfor a safe bundled smoke test covering construction, concat, H5AD, and optional Zarr round-trips.
Route Map
- Use
sub-skills/data-model/SKILL.mdfor constructing, inspecting, mutating, validating, slicing, copying, or repairing in-memoryAnnDataobjects and aligned containers such asX,obs,var,layers,obsm,varm,obsp,varp,uns, andraw. - Use
sub-skills/storage-io/SKILL.mdfor.h5ad, Zarr, backed mode, lazy reads, sparse on-disk datasets, element-levelread_elem/write_elem, encoding metadata, compression, chunking, and I/O troubleshooting. - Use
sub-skills/combining-data/SKILL.mdforanndata.concat, mapping-vs-sequence keys, merge and join decisions, batch labels, duplicate names, pairwise graph retention,AnnCollection, andexperimental.concat_on_disk. - Use
sub-skills/accessors-extensions/SKILL.mdforanndata.acc.Areferences, reusable validation or plotting helpers, JSON/string reference forms,register_anndata_namespace, and extension namespace debugging.
Common Workflows
- For a new object, start with
data-model: confirmX.shape == (len(obs), len(var)), choose stableobs_namesandvar_names, add aligned arrays only when their leading axes match, then run the bundled structure inspector when shape problems are likely. - For persistence, move to
storage-io: choose.h5adfor single-file exchange or Zarr for directory/object-store workflows, validate round-trips with a tiny fixture, and use backed/lazy reads only when their access constraints fit the task. - For multi-dataset integration, use
combining-data: decideaxis,join,merge,uns_merge,label,keys,index_unique,fill_value, and whether memory pressure requiresAnnCollectionorconcat_on_disk. - For reusable library code, use
accessors-extensions: represent fields withA.obs[...],A.obsm[...][:, i], orA.layers[...], validate references before indexing, and keep extension namespaces small and explicitly typed.
Shared References And Scripts
- Read
references/troubleshooting.mdfor cross-cutting install/import, optional dependency, data validation, API misuse, storage backend, and workflow-routing issues before diving into sub-skill-specific troubleshooting. - Read
references/repo-provenance.mdwhen deciding whether this generated skill is stale against a newer AnnData checkout or release. references/repo-routing-metadata.jsonis structured metadata used by DisCo's managedrepo-skills-routerimport.- Run
scripts/smoke_anndata_core.pyto validate import, core object construction, concat behavior, and optional H5AD/Zarr round-trips with tiny temporary fixtures.
Decision Points
- Use sparse
Xand sparse layers when data is mostly zero; dense arrays are simpler for tiny examples but can hide memory pressure. - Treat
.rawas an intentional snapshot of originalX,var, andvarm; later.varmutations do not automatically update.raw.var. - Use
.copy()before mutating subsets when parent preservation or warning-free behavior matters. - Use
join="inner"for conservative concat across features andjoin="outer"only when downstream code can handle missing values or sparse zero fill. - For
anndata.concat, use mapping keys or sequencekeys, not both, when creating batch labels. - Use backed mode for limited H5AD inspection and reads; do not assume every in-memory mutation works without materializing.
- Treat
experimentalAPIs as useful but less stable; mention optional dependencies and deprecations such asAnnLoadermoving towardannbatch.Loaderwhen relevant.
Troubleshooting Priority
- Verify the import, installed version, and optional extras relevant to the task.
- Reproduce with a tiny
AnnDataobject before scaling to large files or many batches. - Check shapes and names on every aligned slot.
- Isolate storage problems with a fresh tiny H5AD or Zarr round-trip.
- For concat surprises, print
shape,obs_names,var_names, label categories,.uns.keys(), and relevant.obsm/.varm/.obspkeys. - For accessor or extension errors, validate references and namespace signatures before optional plotting, storage, or downstream package imports.
