Exemple #1
0
    def select(self, selector) -> Selector:
        """

        :param selector: A mongo-like query of the underlying dataframe
        :return:
        >>> _docs = [
        ...  {'bt': 0, 'tt': 5, 'tag': 'small'},
        ...  {'bt': 10, 'tt': 15, 'tag': 'small'},
        ...  {'bt': 20, 'tt': 25, 'tag': 'small'},
        ...  {'bt': 30, 'tt': 35, 'tag': 'big'},
        ...  {'bt': 40, 'tt': 45, 'tag': 'big'},
        ...  {'bt': 50, 'tt': 55, 'tag': 'big'}]
        >>> import pandas as pd
        >>> selector = MgDfSelector(_df=pd.DataFrame(_docs))
        >>> len(selector)
        6
        >>> selection = selector.select({"tag": {"$eq": 'small'}})
        >>> len(selection)
        3
        >>> _print_docs(selection)
        {'bt': 0, 'tag': 'small', 'tt': 5}
        {'bt': 10, 'tag': 'small', 'tt': 15}
        {'bt': 20, 'tag': 'small', 'tt': 25}
        >>> selection = selector.select({'bt': {"$gte": 20}, 'tt': {"$lt": 45}})
        >>> _print_docs(selection)
        {'bt': 20, 'tag': 'small', 'tt': 25}
        {'bt': 30, 'tag': 'big', 'tt': 35}
        """
        selector_file_func = Query(selector).match
        lidx = list(map(selector_file_func, self._df.to_dict(orient='rows')))
        return self.__class__(self._df[lidx])
Exemple #2
0
 def _selector_func(self, selector):
     return Query(selector).match
Exemple #3
0
 def select(self, selector) -> Selector:
     selector_file_func = Query(selector).match
     lidx = list(map(selector_file_func, self._docs.to_dict(orient='rows')))
     return self.__class__(self._docs[lidx])