def column_group_by(column, keys):
 from .table import Table
 if isinstance(keys, Table):
  keys = keys.as_array()
 if (not isinstance(keys, np.ndarray)):
  raise TypeError(u'Keys input must be numpy array, but got {0}'.format(type(keys)))
 if (len(keys) != len(column)):
  raise ValueError(u'Input keys array length {0} does not match column length {1}'.format(len(keys), len(column)))
 index = None
 if isinstance(keys, Table):
  index = get_index(keys)
 elif (hasattr(keys, u'indices') and keys.indices):
  index = keys.indices[0]
 if (index is not None):
  idx_sort = index.sorted_data()
 else:
  idx_sort = keys.argsort()
 keys = keys[idx_sort]
 diffs = np.concatenate(([True], (keys[1:] != keys[:(-1)]), [True]))
 indices = np.flatnonzero(diffs)
 out = column.__class__(column[idx_sort])
 out._groups = ColumnGroups(out, indices=indices, keys=keys[indices[:(-1)]])
 return out

def column_group_by ( column , keys ) : from . table import Table if isinstance ( keys , Table ) : keys = keys . as_array ( ) if ( not isinstance ( keys , np . ndarray ) ) : raise TypeError ( u'Keys input must be numpy array, but got {0}' . format ( type ( keys ) ) ) if ( len ( keys ) != len ( column ) ) : raise ValueError ( u'Input keys array length {0} does not match column length {1}' . format ( len ( keys ) , len ( column ) ) ) index = None if isinstance ( keys , Table ) : index = get_index ( keys ) elif ( hasattr ( keys , u'indices' ) and keys . indices ) : index = keys . indices [ 0 ] if ( index is not None ) : idx_sort = index . sorted_data ( ) else : idx_sort = keys . argsort ( ) keys = keys [ idx_sort ] diffs = np . concatenate ( ( [ True ] , ( keys [ 1 : ] != keys [ : ( - 1 ) ] ) , [ True ] ) ) indices = np . flatnonzero ( diffs ) out = column . __class__ ( column [ idx_sort ] ) out . _groups = ColumnGroups ( out , indices = indices , keys = keys [ indices [ : ( - 1 ) ] ] ) return out
get groups for column on specified keys parameters column : column object column to group keys : table or numpy array of same length as col grouping key specifier returns grouped_column : column object with groups attr set accordingly .