Repository navigation
Conversation
What `import array` writes is now what anndata reads back. - F199: a column written into a dataframe is added to its column-order, which anndata reads a frame's columns from; before, `obs/score` exited 0 and anndata never showed it. A column of any dataframe (obs, var, raw/var, or one in obsm or uns) must be 1-D, as long as the frame, in a frame the store has, and not named as its index (which `obs/_index` used to replace), `_index` or `__categories`. - F200: a column of raw/var is measured against raw's own variables; it was written at any length. - F201: an aligned path needs the dimensions it is aligned on, and the refusal names the shape: a scalar into obsm failed with 'tuple index out of range', and a 1-D array into obsp or varp was written, though anndata cannot read a store holding one. - F202: obs and var are no longer matched as bare prefixes. A top-level name outside the AnnData layout, such as `variance_explained`, is refused for what it is: anndata hands every top-level member to `AnnData()` and cannot read a store holding one it does not know. - docs: the import section of commands.md, troubleshooting, and the test map's row for test_validate.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ames - A path inside a column of raw/var (a categorical's categories) is no longer measured against raw's variables as if it were a column, nor fails on a scalar with 'tuple index out of range'; every dimension lookup in validate.py now follows a check that the input has it. - A frame encoded as anything but a dataframe (the dict raw/var 0.17.8 left behind) takes no column; one with no encoding still does, since anndata reads its every member as a column. - MuData's own top-level groups (mod, obsmap, varmap) are written to as before: an .h5mu is HDF5 to import, and `mod/rna/obsm/...` is AnnData. - Messages: a frame's length in rows; shapes with '×' throughout. - Tests: refusals run with --inplace, so the source read afterwards is the store a write would have changed; anndata's refusal of an unknown top-level key on every backend; a text column into a frame with none; an unencoded obs; an .h5mu modality; anndata 0.7's layout. - Docs: the troubleshooting entries for both length messages, MuData's groups and the frame refusal in commands.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
check_target cannot see the store, so it let `mod`, `obsmap` and `varmap` through everywhere, and `import array data.h5ad mod/x` wrote a store anndata cannot read. validate_dimensions, which sees the store and runs in import's precheck, now refuses them unless the store is laid out as a MuData (a `mod` group). It asks the layout, not the root's encoding: open_store stamps AnnData's encoding on the copy an import writes into, so an .h5mu says "anndata" there. The troubleshooting entry for "Row count mismatch" no longer claims the columns of obs and var, which fail with "First dimension mismatch". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Test Results (py3.12)4 074 tests 4 061 ✅ 6m 36s ⏱️ Results for commit 8c53a25. |
Test Results (py3.13)4 074 tests 4 061 ✅ 11m 5s ⏱️ Results for commit 8c53a25. |
Batch B6 of #149: what
import arraywrites is what anndata reads back. It ownsformats/array.pyandformats/validate.py, plus tests and docs.Closes #140 (F199, F200, F201, F202).
What changes
F199 (H):
import array obs/<new>exits 0 but anndata never shows the column.import_npywrote the column into the frame without adding it to the frame'scolumn-order, the list anndata reads a frame's columns from.column-order. A replaced column keeps its place and is listed once. The same root cause applied toobs,varandraw/var, and to frames inobsmoruns, so all of them are fixed.validate_dimensions, soimport's precheck refuses before the store is copied. A column must:obs/_indexexited 0 and anndata'sobs_namesbecame'0.0', '1.0', …._indexand__categories, anndata's own names in a frame, are refused too;raw/var/scorein a store with no raw used to createrawandraw/varas dict mappings: exit 0, and anndata showed a raw copied fromX, without the column;obs) with every member as a column;uns). Listed at the wrong length, it would leave a store anndata cannot read.F200 (M):
raw/var/<col>was written at any length._validate_rawnow measures a column of raw/var against raw's own variables (raw/X's width), as it already didraw/varandraw/varm. Paths inside a column, such as a categorical'scategories, are left alone, as before.F201 (L): a 0-d
.npyintoobsm/varm/obspfailed withError: tuple index out of range.validate_dimensionsread dimensions without checking the input had them. Every such read now follows a check, and an aligned path needs as many dimensions as it is aligned on. The refusal names the shape, e.g.'obsp/s' needs a 6×6 matrix, a row and a column per cell, but the input is 1-D (6).obsporvarp. That used to be written, though anndata cannot read a store holding one (Values of obsp must match dimensions ('obs', 'obs')).obsp's square check no longer refuses with "expected None×None".F202 (L):
obs/varwere matched as bare prefixes. The prefixes are nowobs/,var/,obsm/, … and theX/layersmatch is exact.One departure from the audit. The audit expected a top-level
variance_explainedto be written once the prefix bug was fixed ("anndata keeps unknown top-level keys"). It does not. anndata passes every top-level member toAnnData():variance_explainedthere fails on h5ad, Zarr v2 and v3 withAnnData.__init__() got an unexpected keyword argument;shapefails as a constructor argument;raw.Xbesiderawis "both legacy and current raw formats".So
check_targetrefuses a top-level name outside the layout for that reason, for every import kind, and suggestsuns/<name>. Writing it would have turned a misleading refusal into an unreadable store. A test pins anndata's behaviour.MuData's own groups (
mod,obsmap,varmap) are the exception:importtakes an.h5muas the HDF5 file it is, andmod/rna/obsm/…is AnnData, so they are still written to, as onmain, in a store laid out as a MuData (one with amodgroup).validate_dimensions, which sees the store, refuses them, since anndata could not read the result.open_storestampsencoding-type: anndataon the copy an import writes into.Repros (copies with
WTpointed at this branch)mainstorage/13)DEFECT: imported obs/score exits 0 but anndata does not show the columnOK: an imported obs column is visible to anndatastorage/10)DEFECT: a 5-row column was imported into a 4-row raw/var without a dimension checkOK: a raw/var column of the wrong length is refusedstorage/11)DEFECT: a top-level 'variance_explained' is refused against n_var; a scalar into obsm/ fails with 'tuple index out of range'OK: validate_dimensions matches axis paths exactly and explains scalar refusals(variance_explained:'variance_explained' is outside the AnnData layout … Put it in uns;obsm/s:'obsm/s' needs one row per cell (3), but the input is a scalar.)Tests
Each regression test's docstring starts with its ref. Each checks the result with anndata reading it back, on h5ad, Zarr v2 and Zarr v3, and refusals run with
--inplace, so the source that anndata reads afterwards is the store a write would have changed. Each regression test fails onmain's two source files and passes here. Run against the review round's starting point, so do the tests for the review's points.tests/test_import.py:modandobsmapare refused in an AnnData store;.h5mumodality is still a target.tests/test_validate.py: unit cases for every new refusal; no bare prefix matched; paths inside a raw/var column; encoded and unencoded frames; every name of the layout still a target; MuData's groups refused outside a MuData layout and accepted in one.docs/reference/testing.md:test_validate.py's row.On the final commit (8c53a25), locally on macOS with Python 3.12:
uv run pytest -m "not integration"gives 4274 passed, 9 skipped (357 integration tests deselected);uv run pytest -m perfgives 209 passed.Docs
docs/reference/commands.md,import:docs/troubleshooting.md:Changelog entry (for 0.17.11,
### Fixed)obs,varorraw/varis a column anndata reads(#140).
adata import array data.h5ad obs/score score.npyexited 0 and wrote the column, but leftit out of obs's
column-order, the list anndata reads a frame's columnsfrom, so anndata never showed it and a round trip through anndata dropped
it. The column is now listed, in a frame in
obsmorunstoo, and acolumn it replaces keeps its place. A column of
raw/varis measuredagainst raw's variables, where one of any length was written, and one of a
frame in
unsagainst the frame. A column named as the frame's index, whichit used to replace (
obs/_indexturned obs_names into0.0,1.0, …), or_indexor__categories, is refused, and so is a column of a frame thestore does not hold as a dataframe.
importnames the shape a path needs, where an input lacks a dimension(#140). A scalar
.npyinto
obsm,varm,obsp,varporraw/varmfailed withError: tuple index out of range, and a 1-D array intoobsporvarpwas written,though anndata cannot read a store holding one.
(#140).
varwasmatched as a bare prefix, so
adata import array data.h5ad variance_explained v.npywas measured against var and refused because"var has 2 features". anndata cannot read a store with an element it does
not know at its top level, so every
importnow refuses one, naming thelayout, and suggests
uns/. A MuData.h5mu's ownmod,obsmapandvarmapare still written to in a store laid out as a MuData, and refusedin an AnnData store.
Review
An independent subagent reviewed the diff twice.
The first pass found these, fixed in the second commit:
.h5mumodalities were refused;The second pass found that letting MuData's groups through in
check_targetaccepted them in AnnData stores too; the third commit fixes that. It suggested judging by the root's encoding. I judge by the layout instead, becauseopen_storerestamps the root; a test pins that case.Noticed, not fixed (outside B6's files or findings)
MuData.
.h5murestamps its root asencoding-type: anndata.storage.open_storecallsensure_anndata_root_attrson any store opened to write, as onmain..h5mu, a modality's own layout is not checked: an array asmod,mod/rna/obsormod/rna/obsmbreaks the modality, as onmain.import dictinto a top-levelmod,obsmaporvarmapof an AnnData store is not refused, becausejson_data.pyruns no check that sees the store.import dict uns/table/score …andimport dataframe uns/table/sub …(into a frame in uns or obsm) exit 0, but anndata never shows the member: F199's symptom for other kinds. The fix belongs informats/json_data.pyandformats/dataframe.py.import arrayaccepts a 3-D array intoXorlayers: anndata 0.13 reads it, but refuses to write it back ("violates the AnnData specification").import array data.h5ad X/data v.npywrites into a sparseX's group unchecked (any length).Paths inside an element fail or misjudge, as on
main:obs/<categorical>/categoriesis measured against obs as if it were a column;obs/<col>/codesinto a dataset fails with'Dataset' object has no attribute 'create_dataset';X/subon a dense X fails with "truth value of an array … is ambiguous".A single "the parent is not a group" refusal would make the last two clear.
🤖 Generated with Claude Code