Source code for omegaml.mixins.mdf.filterops

 1from omegaml.mdataframe import MSeries
 2from omegaml.store import Filter, MongoQ
 3
 4
[docs] 5class FilterOpsMixin: 6 """ 7 filter operators on MSeries 8 """ 9 10 def __getfltop(op): 11 def inner(self, other=True): 12 return self.__fltop__(op, other) 13 14 return inner 15 16 def __fltop__(self, op, other): 17 # the actual filter operator 18 q = None 19 for col in self.columns: 20 queryop = f'{col}__{op}' 21 value = other if not isinstance(other, MSeries) else '$' + other.columns[0] 22 qq = MongoQ(**{queryop: value}) 23 if q is None: 24 q = qq 25 else: 26 q = q | qq 27 return Filter(self.collection, q) 28 29 # see https://docs.mongodb.com/manual/reference/operator/query/ 30 __eq__ = __getfltop('eq') 31 __ne__ = __getfltop('ne') 32 __lt__ = __getfltop('lt') 33 __le__ = __getfltop('lte') 34 __gt__ = __getfltop('gt') 35 __ge__ = __getfltop('gte') 36 37 isnull = __getfltop('isnull')