Repository navigation
Conversation
descendants for unknown IDslineage_ids and descendant_ids
audy
force-pushed
the
austin/dev-12348-descendants-unknown-id
branch
from
November 24, 2026 22:30
d6132e3 to
78be915
Compare
audy
commented
Nov 24, 2026
lineage_ids and descendant_idslineage_ids and descendant_ids, fix descendants panicking on nonexistent tax ID
audy
marked this pull request as ready for review
November 25, 2026 00:41
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.
Summary
Taxonomy.lineage_ids(tax_id)andTaxonomy.descendant_ids(tax_id). They do the same traversal aslineage()anddescendants()but returnlist[str]IDs instead of building aTaxonomyNodeper node. On large trees, building those node objects is most of the cost, and some callers only need the IDs.descendants()(and sodescendant_ids()), which panicked on an unknown tax ID. It now raisesTaxonomyError.lineage/descendantsbindings (and the new_idsvariants) now resolve the tax ID to an internal index once and traverse by index, instead of hashing the tax ID string for every field and every step of the traversal. This resulted in a slight speedup.contains(tax_id) -> boolmethod to the RustTaxonomytrait as the single way to check whether a node exists. A tax ID exists ifname()returnsOkfor it; there are no overrides.traverse()uses it to reject unknown start nodes, and Python'stax_id in taxandadd_nodeduplicate check now call it.descendants()(anddescendant_ids()) now return nodes in depth-first order, each node before its own descendants, instead of sorted by tax ID as a string. The lexicographic sort wasn't a meaningful order and was a large part of the cost. The Rust&strdescendantsstill sorts.from_newicknow stores node labels as names and gives each node a positional tax ID (the root is"0"), andto_newickwrites names (whitespace replaced with underscores) instead of tax IDs. Newick labels are optional and often repeated (unlabelled internal nodes, support values), so using them as tax IDs produced duplicates: traversals by ID could skip nodes or loop forever on nested unlabelled nodes. Look nodes up by label withfind_all_by_name. Newick trees now always have unique IDs, sodescendants()never returns duplicates.Release build, current NCBI taxdump,
master(0ce37a9) vs. this PR (e78df5b). Median of 3 runs, each in a fresh process; memory is RSS held by the result (varies by up to ~35 MB between builds for identical code). Lineage is over 100k random bacterial taxa; descendants is of"2"(564k nodes).masterlineagelineage_idsdescendantsdescendant_idstax_id in tax(1M lookups)