Repository navigation
--categorical reads numeric-looking labels as text (#124) - #125
Conversation
A column named in --categorical whose values looked like numbers (leiden's "0", "1", "10") was kept as int64 with only a note, so an export, edit and import of obs lost the clusters' labels, and "007" its zeros. A forced column is now always read as text and stored as a categorical: numbers and True/False keep the text they were written as, and what pandas reads as missing stays a gap, matching pd.read_csv(dtype=str) and anndata's strings_to_categoricals. Past the cap of distinct values it is written as strings, numbers included, as the warning already said. --keep-dtypes and a columns-only import, also raised in #124, are noted in STATUS.md as follow-ups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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. |
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.
Test Results (py3.13)3 817 tests 3 805 ✅ 5m 26s ⏱️ Results for commit 76e414a. ♻️ This comment has been updated with latest results. |
Test Results (py3.12)3 817 tests 3 805 ✅ 10m 4s ⏱️ Results for commit 76e414a. ♻️ This comment has been updated with latest results. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
STATUS.md keeps both follow-ups: #124's and the GitHub releases note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #124.
adata import dataframe … --categorical leidenused to keep a column of numeric-looking labels ("0","1","10") as int64 and print only a note. So anexport dataframe→ edit →import dataframeround trip lost the most common obs categoricals.A column named in
--categoricalis now always read as text and stored as a categorical, whatever its values look like:0,1,10stay labels, with categories in anndata's natural order (0, 1, 2, 10), and007keeps its zeros;pd.read_csv(dtype=str)followed bystrings_to_categoricals, which the new tests use as the oracle;There is no change to
formats/table.py: the scan already keeps every column's distinct values as written.Not in this PR. Both are noted in STATUS.md under follow-ups:
--keep-dtypes, to keep the existing frame's encodings (category order,ordered, dtypes);Changelog entry (for 0.17.7)
Fixed
--categoricalkeeps numeric-looking labels (#124).adata import dataframe … --categorical leidenused to leave leiden clusters0,1,10as int64. Columns named in--categoricalare now read as text and stored as categoricals whatever their values, so an export → edit → import round trip keeps them, and007keeps its zeros.Tests
test_numeric_labels_named_categorical_survive_a_round_trip(h5ad, zarr2, zarr3) is the issue's round trip, with a"007"/"7"column and a gap. It fails onmain.test_categorical_overrides_still_applynow forces a float column, a whole-number column with a gap and a True/False column, and checks them against the oracle.test_a_forced_numeric_column_past_the_cap_is_written_as_strings.leiden: categorywith categories['0', '1', '2', '10'].🤖 Generated with Claude Code