Source code for omegaml.mixins.mdf.filterops

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