def _eager(self, pytmp=True): if not self._computed: # top-level call to execute all subparts of self._ast sb = self._ast._eager() if pytmp: h2o.rapids(ExprNode._collapse_sb(sb), self._id) sb = ["%", self._id," "] self._update() # fill out _nrows, _ncols, _col_names, _computed return sb
def _eager(self, pytmp=True): if not self._computed: # top-level call to execute all subparts of self._ast sb = self._ast._eager() if pytmp: res = h2o.rapids(ExprNode._collapse_sb(sb), self._id) # t = res["result_type"] # if t in [1,3]: sb = ["#{} ".format(res["scalar"])] # elif t in [2,4]: sb = ["\"{}\"".format(res["string"])] sb = ["%", self._id," "] self._update() # fill out _nrows, _ncols, _col_names, _computed return sb
def rapids(expr, id=None): """ Fire off a Rapids expression. :param expr: The rapids expression (ascii string). :return: The JSON response of the Rapids execution """ if isinstance(expr, list): expr = ExprNode._collapse_sb(expr) expr = "(= !{} {})".format(id,expr) if id is not None else expr result = H2OConnection.post_json("Rapids", ast=urllib.quote(expr), _rest_version=99) if result['error'] is not None: raise EnvironmentError("rapids expression not evaluated: {0}".format(str(result['error']))) return result
def __setitem__(self, b, c): """ Replace a column in an H2OFrame. :param b: A 0-based index or a column name. :param c: The vector that 'b' is replaced with. :return: Returns this H2OFrame. """ update_index=-1 if isinstance(b, (str,unicode)): update_index=self.col_names().index(b) if b in self.col_names() else self._ncols elif isinstance(b, int): update_index=b lhs = ExprNode("[", self, b, None) if isinstance(b,H2OFrame) else ExprNode("[", self, None, update_index) rhs = c._frame() if isinstance(c,H2OFrame) else c col_name = b if (update_index==self._ncols and isinstance(b, (str, unicode))) else ( c._col_names[0] if isinstance(c, H2OFrame) else "" ) sb = ExprNode(",", ExprNode("=",lhs,rhs), ExprNode("colnames=",self,update_index,col_name))._eager() if update_index >= self.ncol() else ExprNode("=",lhs,rhs)._eager() h2o.rapids(ExprNode._collapse_sb(sb)) self._update()
def __setitem__(self, b, c): """ Replace a column in an H2OFrame. :param b: A 0-based index or a column name. :param c: The vector that 'b' is replaced with. :return: Returns this H2OFrame. """ update_index=-1 if isinstance(b, basestring): update_index=self.col_names.index(b) if b in self.col_names else self._ncols elif isinstance(b, int): update_index=b if isinstance(b, tuple): bb = b[1] if isinstance(bb, basestring): update_index=self.col_names.index(bb) if bb in self.col_names else self._ncols elif isinstance(bb, int): update_index=bb lhs = ExprNode("[", self,b[0],b[1]) else: lhs = ExprNode("[", self, b, None) if isinstance(b,H2OFrame) else ExprNode("[", self, None, update_index) rhs = c._frame() if isinstance(c,H2OFrame) else c col_name = b if (update_index==self._ncols and isinstance(b, basestring)) else ( c._col_names[0] if isinstance(c, H2OFrame) else "" ) sb = ExprNode(",", ExprNode("=",lhs,rhs), ExprNode("colnames=",self,update_index,col_name))._eager() if update_index >= self.ncol else ExprNode("=",lhs,rhs)._eager() h2o.rapids(ExprNode._collapse_sb(sb)) self._update()