Esempio n. 1
0
 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
Esempio n. 2
0
  def setNames(self,names):
    """
    Change the column names to `names`.

    :param names: A list of strings equal to the number of columns in the H2OFrame.
    :return: None. Rename the column names in this H2OFrame.
    """
    h2o.rapids(ExprNode("colnames=", self, range(self.ncol()), names)._eager())
    self._update()
    return self
Esempio n. 3
0
  def setNames(self,names):
    """
    Change the column names to `names`.

    :param names: A list of strings equal to the number of columns in the H2OFrame.
    :return: None. Rename the column names in this H2OFrame.
    """
    h2o.rapids(ExprNode("colnames=", self, range(self.ncol), names)._eager())
    self._update()
    return self
Esempio n. 4
0
  def setName(self,col=None,name=None):
    """
    Set the name of the column at the specified index.

    :param col: Index of the column whose name is to be set.
    :param name: The new name of the column to set
    :return: the input frame
    """
    if not isinstance(col, int) and self.ncol() > 1: raise ValueError("`col` must be an index. Got: " + str(col))
    if self.ncol() == 1: col = 0
    h2o.rapids(ExprNode("colnames=", self, col, name)._eager())
    self._update()
    return self
Esempio n. 5
0
  def setName(self,col=None,name=None):
    """
    Set the name of the column at the specified index.

    :param col: Index of the column whose name is to be set.
    :param name: The new name of the column to set
    :return: the input frame
    """
    if not isinstance(col, int) and self.ncol > 1: raise ValueError("`col` must be an index. Got: " + str(col))
    if self.ncol == 1: col = 0
    h2o.rapids(ExprNode("colnames=", self, col, name)._eager())
    self._update()
    return self
Esempio n. 6
0
  def setLevels(self, levels):
    """
    Works on a single categorical vector. New domains must be aligned with the old domains. This call has SIDE
    EFFECTS and mutates the column in place (does not make a copy).

    :param level: The level at which the column will be set (a string)
    :param x: A single categorical column.
    :param levels: A list of strings specifying the new levels. The number of new levels must match the number of
    old levels.
    :return: None
    """
    h2o.rapids(ExprNode("setDomain", self, levels)._eager())
    self._update()
    return self
Esempio n. 7
0
  def setLevels(self, levels):
    """
    Works on a single categorical vector. New domains must be aligned with the old domains. This call has SIDE
    EFFECTS and mutates the column in place (does not make a copy).

    :param level: The level at which the column will be set (a string)
    :param x: A single categorical column.
    :param levels: A list of strings specifying the new levels. The number of new levels must match the number of
    old levels.
    :return: None
    """
    h2o.rapids(ExprNode("setDomain", self, levels)._eager())
    self._update()
    return self
Esempio n. 8
0
  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()
Esempio n. 9
0
 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
Esempio n. 10
0
  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()