Esempio n. 1
0
def is_categorical(data, c=None):
    from pandas.api.types import is_categorical_dtype as cat

    if c is None:
        return cat(data)  # if data is categorical/array
    if not is_view(data):  # if data is anndata view
        strings_to_categoricals(data)
    return isinstance(c, str) and c in data.obs.keys() and cat(data.obs[c])
Esempio n. 2
0
def is_categorical(adata, c):
    adata._sanitize(
    )  # Indentify array of categorical type and transform where applicable
    return isinstance(c, str) and (c in adata.obs.keys() and cat(adata.obs[c])
                                   or is_color_like(c))
Esempio n. 3
0
def is_categorical(adata, c):
    from pandas.api.types import is_categorical as cat
    strings_to_categoricals(adata)
    return isinstance(c, str) and c in adata.obs.keys() and cat(adata.obs[c])
Esempio n. 4
0
def n_categories(adata, c):
    from pandas.api.types import is_categorical as cat
    return len(adata.obs[c].cat.categories) if (c in adata.obs.keys()
                                                and cat(adata.obs[c])) else 0
Esempio n. 5
0
def is_categorical(adata, c):
    from pandas.api.types import is_categorical as cat
    strings_to_categoricals(adata)
    str_not_var = isinstance(c, str) and c not in adata.var_names
    return str_not_var and (c in adata.obs.keys() and cat(adata.obs[c])
                            or is_color_like(c))