Skip to content

Fix ranks like "domain" being rewritten to "no rank" on save - #83

Merged
audy merged 2 commits into
masterfrom
worktree-fix-domain-rank-rewrite
Nov 5, 2026
Merged

audy merged 2 commits into
masterfrom
worktree-fix-domain-rank-rewrite

Conversation

@audy

@audy audy commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

TaxRank::to_ncbi_rank had a catch-all _ => "no rank" arm. Domain, Subdomain, Realm, the Division family, Legion/Cohort variants and ~20 others fell through it. Both the NCBI writer and the JSON serializer use it, so saving or round-tripping a current NCBI taxdump (where Bacteria/Archaea/Eukaryota are domain) silently rewrote those ranks to no rank. Reads looked fine because the Python rank property goes through Display, which was exhaustive.

Fix

  • Move the exhaustive Display table into TaxRank::as_str and have both Display and to_ncbi_rank delegate to it. A variant without a string is now a compile error.
  • Add from_str entries for variants that previously could never be written and so were never parsed: superdivision, division, subdivision, infradivision, series fish, series lepidoptera, group lepidoptera, subseries botany, individual.
    • Note: "division" was intentionally unmapped before because it is ambiguous with botanical phylum. It now maps to TaxRank::Division so the library can read back what it writes. Happy to revert that one if you prefer the error.
  • Tests: rank round-trip tests now assert equality rather than is_ok; the NCBI fixture uses domain for Bacteria and asserts the rank survives save/load. Confirmed that assertion fails on master (Unspecified) and passes here.

audy added 2 commits November 4, 2026 15:51
TaxRank::to_ncbi_rank had a catch-all arm that mapped Domain and ~20
other variants to "no rank". The NCBI and JSON writers go through it,
so round-tripping a current NCBI taxdump silently lost those ranks.

Share one exhaustive string table between Display and to_ncbi_rank,
add from_str entries for the variants that previously could never be
written, and assert in tests that every rank round-trips unchanged.
@audy
audy marked this pull request as ready for review November 5, 2026 00:00
@audy
audy merged commit fcf9192 into master Nov 5, 2026
27 checks passed
@audy
audy deleted the worktree-fix-domain-rank-rewrite branch November 5, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants