OR, XOR and NOT in filters #296
Open
yfukai wants to merge 12 commits into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #296 +/- ##
==========================================
+ Coverage 87.81% 88.05% +0.23%
==========================================
Files 57 57
Lines 4998 5090 +92
Branches 877 900 +23
==========================================
+ Hits 4389 4482 +93
+ Misses 384 383 -1
Partials 225 225 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The remote branch carried a wholesale unification of AttrComparison/AttrFilter into Attr (~600-line diff). Local opted for the smaller targeted change (AttrFilter.to_attr) instead. Resolved by taking local's version of attrs.py and discarding origin's other changes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
Author
|
Of note: there's a path to merge |
JoOkuma
approved these changes
Jun 1, 2026
| return f.op(getattr(table, str(f.column)), f.other) | ||
|
|
||
| if f.op == "not": | ||
| return sa.not_(_to_sql_clause(f.operands[0], table)) |
Member
There was a problem hiding this comment.
Can you expand on why you can index 0 here and not look at all operands?
- Add `Filter(ABC)` defining the shared interface (`to_attr`, `columns`,
boolean dunders); `AttrComparison` and `AttrFilter` now inherit, removing
~50 lines of duplicated `& | ^ ~` dunders.
- Replace the `FilterInput` Union alias with `Filter` directly across all
consumers (attrs, graph backends, indexed filter).
- Merge `_FILTER_LOGICAL_OPS` into `_FILTER_OP_SYMBOLS` — the symbol dict's
keys are the single source of truth for valid op names.
- Drop dead `__r{eq,ne,lt,le,gt,ge}__` stubs from both `Attr` and
`AttrComparison` and their `_setup_ops` generators. Python's data model
uses `__eq__`/`__ne__` symmetrically for `==`/`!=` and the OPPOSITE op
for `<>≤≥` reflection, so these were never called.
- Simplify `_delegate_comparison_operator`: drop the now-unused `reverse`
parameter.
- Widen `MembershipExprInput` to `Sequence[Scalar] | np.ndarray` so the
type matches the runtime behavior accepted by `is_in`.
- Fix typo `attrr_comparision` and drop a stale unused `df` in tests.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
yfukai
commented
Jun 8, 2026
Contributor
Author
yfukai
left a comment
There was a problem hiding this comment.
I believe the code is okay.
Contributor
Author
|
The failing CI is not related to the code, but is a temporary error on Codecov. |
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.
Human summary
Currently only "AND" concatenation is supported for the
AttrComparison. I updated theAttrcodebase to support intuitive "OR", "XOR" and "NOT" operations (nowAttrFilterexists for this purpose). I chose not to allow combining node and edge filters inAttrFiltersince that would complicate the codebase significantly.Copilot summary
This pull request introduces a new
AttrFilterclass to enable expressive, compound boolean filtering of node and edge attributes using logical operators (&,|,^,~). It updates the API throughout the codebase to support these compound filters, allowing for more flexible and readable queries.Major new feature: Compound attribute filtering
AttrFilterclass, which allows combiningAttrComparisonobjects (and nestedAttrFilters) using logical operators (&,|,^,~) to build complex boolean filters for graph queries. This enables expressions like(NodeAttr("t") == 1) | (NodeAttr("t") == 2)and ensures that filters are type-safe and validated.API and type annotation updates
filter,split_attr_comps, etc.) to accept bothAttrComparisonandAttrFilterobjects, using the newFilterInputtype alias. This ensures that all relevant methods and internal logic can handle compound filters transparently. [1] [2] [3] [4] [5] [6] [7]Filtering logic and backend improvements
Documentation and usage examples
attrs.pyto explain and demonstrate the use of logical operators for combining attribute comparisons, with clear code examples for users.Comprehensive testing for new filter functionality
AttrFiltercovering construction, operator overloading, error handling, filter splitting, and evaluation with polars, ensuring robust and correct behavior for all supported logical operations. [1] [2]