def write_csvs(dirname: PathLike, adata: AnnData, skip_data: bool = True, sep: str = ','):
    """See :meth:`~anndata.AnnData.write_csvs`.
    """
    dirname = Path(dirname)
    if dirname.suffix == '.csv':
        dirname = dirname.with_suffix('')
    logger.info("writing '.csv' files to %s", dirname)
    if not dirname.is_dir():
        dirname.mkdir(parents=True, exist_ok=True)
    dir_uns = dirname / 'uns'
    if not dir_uns.is_dir():
        dir_uns.mkdir(parents=True, exist_ok=True)
    d = dict(
        obs=adata._obs,
        var=adata._var,
        obsm=adata._obsm.to_df(),
        varm=adata._varm.to_df(),
    )
    if not skip_data:
        d['X'] = pd.DataFrame(
            adata._X.toarray() if issparse(adata._X) else adata._X)
    d_write = {**d, **adata._uns}
    not_yet_raised_sparse_warning = True
    for key, value in d_write.items():
        if issparse(value):
            if not_yet_raised_sparse_warning:
                warnings.warn('Omitting to write sparse annotation.')
                not_yet_raised_sparse_warning = False
            continue
        filename = dirname
        if key not in {'X', 'var', 'obs', 'obsm', 'varm'}:
            filename = dir_uns
        filename /= '{}.csv'.format(key)
        df = value
        if not isinstance(value, pd.DataFrame):
            value = np.array(value)
            if np.ndim(value) == 0:
                value = value[None]
            try:
                df = pd.DataFrame(value)
            except Exception as e:
                warnings.warn('Omitting to write {!r}.'.format(key), type(e))
                continue
        df.to_csv(
            filename, sep=sep,
            header=key in {'obs', 'var', 'obsm', 'varm'},
            index=key in {'obs', 'var'},
        )
def write_csvs ( dirname : PathLike , adata : AnnData , skip_data : bool = True , sep : str = ',' ) : dirname = Path ( dirname ) if dirname . suffix == '.csv' : dirname = dirname . with_suffix ( '' ) logger . info ( "writing '.csv' files to %s" , dirname ) if not dirname . is_dir ( ) : dirname . mkdir ( parents = True , exist_ok = True ) dir_uns = dirname / 'uns' if not dir_uns . is_dir ( ) : dir_uns . mkdir ( parents = True , exist_ok = True ) d = dict ( obs = adata . _obs , var = adata . _var , obsm = adata . _obsm . to_df ( ) , varm = adata . _varm . to_df ( ) , ) if not skip_data : d [ 'X' ] = pd . DataFrame ( adata . _X . toarray ( ) if issparse ( adata . _X ) else adata . _X ) d_write = { ** d , ** adata . _uns } not_yet_raised_sparse_warning = True for key , value in d_write . items ( ) : if issparse ( value ) : if not_yet_raised_sparse_warning : warnings . warn ( 'Omitting to write sparse annotation.' ) not_yet_raised_sparse_warning = False continue filename = dirname if key not in { 'X' , 'var' , 'obs' , 'obsm' , 'varm' } : filename = dir_uns filename /= '{}.csv' . format ( key ) df = value if not isinstance ( value , pd . DataFrame ) : value = np . array ( value ) if np . ndim ( value ) == 0 : value = value [ None ] try : df = pd . DataFrame ( value ) except Exception as e : warnings . warn ( 'Omitting to write {!r}.' . format ( key ) , type ( e ) ) continue df . to_csv ( filename , sep = sep , header = key in { 'obs' , 'var' , 'obsm' , 'varm' } , index = key in { 'obs' , 'var' } , )
See :meth:`~anndata.AnnData.write_csvs`.