Created
September 27, 2022 11:37
-
-
Save clungzta/2bf886901113cdbaf566d7ee3b940668 to your computer and use it in GitHub Desktop.
I ended up switching to df.query(), but keeping this dummy code here for reference
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
# Create class for handling filters with logical operations | |
class Filter(Generic[T]): | |
def __init__(self, name: str, value: T, op: str = "=="): | |
self.name = name | |
self.value = value | |
self.op = op | |
if type(value) == str: | |
if op == "==": | |
self.op = "eq" | |
elif op == "!=": | |
self.op = "neq" | |
elif op == ">": | |
self.op = "gt" | |
elif op == ">=": | |
self.op = "gte" | |
elif op == "<": | |
self.op = "lt" | |
elif op == "<=": | |
self.op = "lte" | |
elif op == "contains": | |
self.op = "contains" | |
elif op == "not contains": | |
self.op = "notContains" | |
elif op == "unknown": | |
self.op = "unknown" | |
def __and__(self, other: Filter): | |
return Filter(self.name, self.value & other.value) | |
def __or__(self, other: Filter): | |
return Filter(self.name, self.value | other.value) | |
def __invert__(self): | |
return Filter(self.name, ~self.value) | |
def __repr__(self): | |
return f"Filter({self.name}, {self.value})" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment