Beispiel #1
0
    def compile_impl(self) -> List[str]:
        cols_c = [item
                  for item in self.predicate.compile(self.parent)]

        return flatlist(
            cols_c,
            f"{self.varname} = {self.parent.varname}.loc[{self.parent.varname}_{self.predicate.expr.varname}]"
        )
Beispiel #2
0
 def compile_impl(self) -> List[str]:
     cols_c = [item
               for expr in self.columns
               for item in expr.compile(self.parent)]
     return flatlist(
         cols_c,
         f"{self.varname} = {self.parent.varname}",
         [f"{self.varname}['{col.get_name()}'] = {self.parent.varname}_{col.expr.varname}"
          for col in self.columns])
Beispiel #3
0
    def compile_impl(self) -> List[str]:
        names = [x.get_name()
                 for x in self.by]
        orders = [not isinstance(x.expr, Desc)
                  for x in self.by]

        return flatlist(f"{self.varname} = {self.parent.varname}.sort_values(",
                        f"by={names},ascending={orders}",
                        f").reset_index(drop=True)")
Beispiel #4
0
 def compile(self) -> List[str]:
     return flatlist(
         self.lhs.compile(),
         self.rhs.compile(),
         f"{self.varname} = {self.lhs.varname}.merge(",
         f"    {self.rhs.varname},",
         f"    how='{self.how}',",
         f"    on={list(map(lambda x: x.get_name(), self.on))}",
         f")"
     )
Beispiel #5
0
    def _compile(self):

        parameters = ','.join(self.ast.inputs)

        module = flatlist(f"def compute({parameters}):", "    import pandas",
                          "    import operator", "    import numpy as np",
                          ["    " + line for line in self.ast.compile()],
                          f"    return {self.ast.varname}", "\n")

        return module
Beispiel #6
0
 def compile_impl(self) -> List[str]:
     cols_c = [item
               for expr in self.columns
               for item in expr.compile(self.parent)]
     return flatlist(
         cols_c,
         f"{self.varname} = pandas.DataFrame" + "({",
         [f"    '{expr.get_name()}': {self.parent.varname}_{expr.expr.varname},"
          for expr in self.columns],
         "})"
     )
Beispiel #7
0
    def compile_impl(self) -> List[str]:
        if any(map(lambda x: isinstance(x.expr, Count), self.aggs)):
            add_c = [f"{self.parent.varname}['COUNTS'] = 1"]
        else:
            add_c = []

        return flatlist(
            add_c,
            f"{self.varname} = {self.parent.varname}.groupby({list(self.grps)})" +
            ".agg(**{",
            ["    " + f"'{agg.get_name()}': {agg.compile(self.parent)},"
             for agg in self.aggs],
            "}).reset_index()"
        )
Beispiel #8
0
 def compile(self) -> List[str]:
     inputs_key = list(self.inputs)[0]
     return flatlist(
         f"{self.varname} = {inputs_key}.copy()"
     )
Beispiel #9
0
 def compile_impl(self) -> List[str]:
     return flatlist(f"{self.varname} = {self.parent.varname}.drop(",
                     f"columns={self.columns}",
                     f").reset_index(drop=True)")
Beispiel #10
0
 def compile_impl(self) -> List[str]:
     return flatlist(f"{self.varname} = {self.parent.varname}.head({self.n})")