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}]" )
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])
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)")
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")" )
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
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], "})" )
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()" )
def compile(self) -> List[str]: inputs_key = list(self.inputs)[0] return flatlist( f"{self.varname} = {inputs_key}.copy()" )
def compile_impl(self) -> List[str]: return flatlist(f"{self.varname} = {self.parent.varname}.drop(", f"columns={self.columns}", f").reset_index(drop=True)")
def compile_impl(self) -> List[str]: return flatlist(f"{self.varname} = {self.parent.varname}.head({self.n})")