Filter-context auto-aggregation across methods (#118)#142
Merged
Conversation
This was referenced Apr 24, 2026
- Under apply_filter only, a Comparison with unqualified same-kind refs auto-aggregates across methods: nanmin for <, <=; nanmax for >, >=. "Any method passes" semantics. - Narrow scope: directional comparisons only; not in sort, not in score arithmetic; cross-kind comparisons stay strict. - EvalContext(df, filter_context=True) exposed for hand-rolled evaluations outside apply_filter. - Internal ctx._method_override drives the per-method binding loop; Field.eval honors it when self.method is None and kind matches.
8af0431 to
2bfe59a
Compare
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
Closes #118. Inside
apply_filter, aComparisonwith unqualified same-kind refs auto-aggregates across methods instead of raising the ambiguity error:Aggregator is picked by the comparison direction:
<,<=nanminacross methods(aff[m1] < k) | (aff[m2] < k) | ...>,>=nanmaxacross methods(aff[m1] > k) | (aff[m2] > k) | ...Scope (narrow on purpose)
Auto-agg fires only when all of these hold:
Comparisonwith<,<=,>, or>=.apply_filtersetsEvalContext.filter_context=True).Fieldrefs in the comparison are the same kind. Cross-kind (affinity.rank <= processing.rank) stays strict.apply_sort, scalar score arithmetic (0.5 * ba.score + 0.5 * el.score),==/!=, and qualified refs (Affinity['netmhcpan'] <= 500) all keep the current strict behavior.Changes
EvalContext(df, filter_context=False)— public kwarg.apply_filtersets it toTrue.EvalContext._method_override— internal(kind_value, method)tuple the Comparison auto-agg loop sets when iterating per method.Field.evalhonorsctx._method_overridewhenself.method is Noneand kind matches.Comparison.eval— new_should_auto_aggregategate +_auto_aggregateloop that evals both sides per method and aggregates LHS via nanmin/nanmax and RHS via the opposite (for the "any method pair" union interpretation)._collect_unqualified_kinds(node)— tree walker.Back-compat
One test in
tests/test_io_lens.pypreviously assertedapply_filter(r.df, Affinity <= 500)raised on a multi-model LENS frame. That was the behavior being relaxed. Replaced with:test_unqualified_autoaggregates_in_filter— verifies no raise + valid shape.test_unqualified_ambiguous_still_raises_in_sort— verifies the sort path keeps strict.No other callers were relying on the filter-side raise.
Test plan
<=/<auto-agg via nanmin;>=/>via nanmaxapply_sortstill raisesAmbiguouson unqualified multi-method refs(Affinity.value <= 200).evaluate(df)outside filter still raisesAffinity.rank <= Processing.rank) stays strict==/!=stay strictAffinity['mhcflurry'] <= 200) bypasses auto-agg(aff <= 200) & (aff.score >= 0.5)) auto-aggs each comparisonConst >= Field(Const on left) mirrors correctlypytest tests/→ 1192 passed, 3 skipped