Repository navigation
Leave a layer narrower than the assay out of as_anndata, with a warning - #147
Merged
Merged
Conversation
…ng (#141) scale_data() scales only the variable features unless it is given others, so scale.data has one row per variable feature, and AnnData rejects a layer that is not as wide as var. as_anndata raised a ValueError from inside AnnData on any object that had been through normalize_data, find_variable_features and scale_data, in either assay class. A layer with fewer features than the assay is now left out, and the warning names it and says how to keep it: scale_data(obj, features=obj.feature_names()) before converting. It is not padded, because from_anndata turns every layer back into an assay layer and padded rows would read back as scaled values that never were. No test had converted an object that had been scaled. The new ones do, for both assay classes, and were mutation-tested both ways: with the guard removed they fail with the issue's ValueError, and with it over-broad the layers that fit go missing. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #141.
scale_data()scales only the variable features unless it is given others, soscale.datahas one row per variable feature.as_anndatawrote every non-default layer intolayersunchanged, and AnnData rejects a layer that is not as wide asvar, so the conversion raised aValueErroron any object that had been throughnormalize_data,find_variable_featuresandscale_data.The change. A layer with fewer features than the assay is left out, with a
UserWarningthat names it, says how many features it holds against the assay's, and says how to keep it:scale_data(obj, features=obj.feature_names())before converting. This is the issue's first suggestion. I did not pad, becausefrom_anndataturns every layer back into an assay layer, so padded rows would read back as scaled values that never were. A layer that covers every feature is exported exactly as before.Both assay classes. The issue only tried
Assay5. The legacyAssaybranch writes its scale layer asscale_dataand fails the same way, so the guard sits where the two branches meet, and the tests run both.Not changed, but found while checking. An object whose layers have been split (
split_layers) fails earlier, inXitself: the default layer becomescounts.A, which has only some of the cells, so AnnData reports thatobshas more rows thanX. That is a different problem from this issue and I left it alone.Verification
(1500, 2863).tests/test_anndata_compat.pygains five tests. They run the standard workflow throughas_anndatafor both assay classes, check that a full-widthscale.datais still exported with the right values and no warning, and check that the result goes back throughfrom_anndata. No existing test had converted an object that had been scaled.ValueError(both classes and the round trip); with it over-broad, so that every extra layer is dropped, four fail.mkdocs --strictbuild with the new paragraph indocs/interop.md. ruff findings incompat/anndata.pyare unchanged (5), and mypy still reports its 4 baseline errors in 2 files.No release is needed for this change on its own. The CHANGELOG entry is under
[Unreleased]→ Fixed.🤖 Generated with Claude Code