nearest takes ties="first" - #38
Merged
Merged
Conversation
`ruranges.numpy.nearest(..., ties="first")` reports one neighbour per distance instead of every neighbour at that distance, binding `ruranges_core::nearest::nearest_with_ties`. The default, `"all"`, is what nearest has always done, and the kernel builds the same output for it as before. With `include_overlaps=True` every interval a query overlaps sits at distance 0, so "all tied neighbours" is "every overlapping interval": on 100 million hg38-like intervals that is 1.1 billion rows against 7.7 million for one per query. The tied rows are never built, so the saving is in memory as well as time. `ties` is parsed in the binding rather than in the kernel's `FromStr`, which panics. A PanicException is not an Exception, so `except Exception` cannot catch it and the interpreter is aborted -- the same trap `direction` fell into and pyranges1 had to guard against. Requires ruranges-core 0.1.13, patched to the adjacent checkout until it is published. Co-Authored-By: Claude Opus 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.
Repo
pyranges/ruranges· baseshared-string-ranker· headnearest-ties· 5 files, +43 −7Why
ruranges.numpy.nearestreports every neighbour at the winning distance. Withinclude_overlaps=Trueevery interval a query overlaps sits at distance 0, so on denseinputs that is one output row per overlapping pair rather than per query: 1.1 billion rows
against 7.7 million on 100 million hg38-like intervals.
What
Binds
ruranges_core::nearest::nearest_with_ties. The default path is the same kernel callit always was.
tiesis parsed in the binding rather than by the kernel'sFromStr, which panics. APanicExceptionis not anException, soexcept Exceptioncannot catch it and theinterpreter is aborted — the trap
directionfell into, and thatpyranges1had to add aguard for. An unknown value raises
ValueErrornaming the two options.Dependencies
Requires ruranges-core 0.1.13 (pyranges/ruranges-core#6). Until that is published the
manifest carries the same development override this repo used for 0.1.12, with a comment
saying to drop it on release.
Version: wheel 0.1.7 → 0.1.8, crate 0.2.5 → 0.2.6.
Verification
Built with
maturin develop --releaseand exercised end to end:The behaviour itself is tested in ruranges-core; the two libraries downstream of this
binding (
pyranges11.4.3,polaranges0.4.0) test the option through it, andpolaranges's randomized oracle checks all three implementations against each other withtiesvarying.