Categorifies the columns `col_names` in `df`.
173342
def series2cat(df:DataFrame, *col_names):
    ""
    for c in listify(col_names): df[c] = df[c].astype('category').cat.as_ordered()
1320416
def fetch_column_names(self, table: str) -> List[str]:
        """"""
        return self.flavour.fetch_column_names(self, table)
443140
def cols_(df,col_list,func,*args,**kwargs):
    
    return _pd.DataFrame({col_name:func(df,col_name,*args,**kwargs) for col_name in col_list})
615810
def _drop_collections(self, df):
        
        all_cols = df.columns
        keep_cols = []

        # Check whether each column contains collections.
        for c in all_cols:
            if len(self._col_type_set(c, df).intersection([set, dict, list])) == 0:
                keep_cols.append(c)
        return df[keep_cols]
308724
def _with_columns(self, columns):
        """"""
        table = type(self)()
        for label, column in zip(self.labels, columns):
            self._add_column_and_format(table, label, column)
        return table
751285
def categorize(df, name, value, criteria,
               color=None, marker=None, linestyle=None, **kwargs):
    
    fdf = df.filter(**kwargs)
    fdf.categorize(name=name, value=value, criteria=criteria, color=color,
                   marker=marker, linestyle=linestyle)

    # update metadata
    if name in df.meta:
        df.meta[name].update(fdf.meta[name])
    else:
        df.meta[name] = fdf.meta[name]
741660
def _ordered_categories(df, categories):
    
    for col, cats in categories.items():
        df[col] = df[col].astype(CategoricalDtype(cats, ordered=True))
    return df
1360092
def types_(self, col: str) -> pd.DataFrame:
        
        cols = self.df.columns.values
        all_types = {}
        for col in cols:
            local_types = []
            for i, val in self.df[col].iteritems():
                #print(i, val, type(val))
                t = type(val).__name__
                if t not in local_types:
                    local_types.append(t)
            all_types[col] = (local_types, i)
        df = pd.DataFrame(all_types, index=["type", "num"])
        return df
1008970
def df(self, qname_predicates:bool=False, keep_variable_type:bool=True) -> pd.DataFrame:
        '''  '''
        local_df = self.df.copy()
        if qname_predicates:
            for col in self.columns:
                local_df.rename({col: self.g.qname(col)})
        if not keep_variable_type:
            pass
            # convert all to strings, watch out for lists
        return local_df
89386
def apply_train(self, df:DataFrame):
        ""
        self.categories = {}
        for n in self.cat_names:
            df.loc[:,n] = df.loc[:,n].astype('category').cat.as_ordered()
            self.categories[n] = df[n].cat.categories
805112
def _label_columns_json(self, cols=None):
        
        ret = {}
        cols = cols or []
        d = {k: v for (k, v) in self.label_columns.items() if k in cols}
        for key, value in d.items():
            ret[key] = as_unicode(_(value).encode("UTF-8"))
        return ret
880600
def strings_to_categoricals(adata):
    
    from pandas import Categorical

    def is_valid_dtype(values):
        from pandas.api.types import is_string_dtype, is_integer_dtype, is_bool_dtype
        return is_string_dtype(values) or is_integer_dtype(values) or is_bool_dtype(values)

    for df in [adata.obs, adata.var]:
        string_cols = [key for key in df.columns if is_valid_dtype(df[key])]
        for key in string_cols:
            c = df[key]
            c = Categorical(c)
            if len(c.categories) < min(len(c), 100): df[key] = c
639013
def _find_key_cols(df):
    """"""
    
    keys = []
    for col in df:
        if len(df[col].unique()) == len(df[col]):
            keys.append(col)
    return keys
346957
def col_rename(df,col_name,new_col_name):
    
    col_list = list(df.columns)
    for index,value in enumerate(col_list):
        if value == col_name:
            col_list[index] = new_col_name
            break
    df.columns = col_list
261061
def filter_cols(model, *filtered_columns):
    
    m = sa.orm.class_mapper(model)
    return list(
        {p.key for p in m.iterate_properties if hasattr(p, "columns")}.difference(
            filtered_columns
        )
    )
837980
def parse_colnames(colnames,coords=None):
    
    cols = []
    if not isinstance(colnames,list):
        colnames = colnames.split(',')
    # parse column names from coords file and match to input values
    if coords is not None and fileutil.isFits(coords)[0]:
        # Open FITS file with table
        ftab = fits.open(coords, memmap=False)
        # determine which extension has the table
        for extn in ftab:
            if isinstance(extn, fits.BinTableHDU):
                # parse column names from table and match to inputs
                cnames = extn.columns.names
                if colnames is not None:
                    for c in colnames:
                        for name,i in zip(cnames,list(range(len(cnames)))):
                            if c == name.lower(): cols.append(i)
                    if len(cols) < len(colnames):
                        errmsg = "Not all input columns found in table..."
                        ftab.close()
                        raise ValueError(errmsg)
                else:
                    cols = cnames[:2]
                break
        ftab.close()
    else:
        for c in colnames:
            if isinstance(c, str):
                if c[0].lower() == 'c': cols.append(int(c[1:])-1)
                else:
                    cols.append(int(c))
            else:
                if isinstance(c, int):
                    cols.append(c)
                else:
                    errmsg = "Unsupported column names..."
                    raise ValueError(errmsg)
    return cols
509555
def _get_unique_categories(self, df):
        """"""

        categories = []
        for col in self._categorical_columns:
            categocial = pd.Categorical(df[col])
            col_categories = list(map(str, categocial.categories))
            col_categories.append('_UNKNOWN')
            categories.append(col_categories)
        return categories