spatialdata icon indicating copy to clipboard operation
spatialdata copied to clipboard

automatic backing of sdata.tables

Open ArneDefauw opened this issue 1 year ago • 2 comments

I was testing the new mutlitple tables feature on the main branch, and noticed that automatic backing of sdata.tables to the backing zarr store no longer works (or I fail to get it working). This is how it used to work:


import anndata as ad
import numpy as np
import pandas as pd
from spatialdata import SpatialData
import spatialdata
import os

path=""

n_cells = 100
n_genes = 50

# Creating random data
X = np.random.randn(n_cells, n_genes)
obs = pd.DataFrame(index=[f'cell_{i}' for i in range(n_cells)])
var = pd.DataFrame(index=[f'gene_{i}' for i in range(n_genes)])

adata = ad.AnnData(X=X, obs=obs, var=var)

adata.obs['cell_type'] = ['type1' if i < n_cells // 2 else 'type2' for i in range(n_cells)]
adata.var['highly_variable'] = np.random.choice([True, False], size=n_genes)


sdata=SpatialData()
sdata.write( os.path.join( path, "sdata_dummy.zarr" ) )

sdata.tables[ "dummy_table" ] = spatialdata.models.TableModel.parse( adata,
)

assert sdata.table is not None # this is ok

sdata=SpatialData.read( os.path.join( path, "sdata_dummy.zarr" ) )
sdata

assert sdata.table is not None # this gives assertionerror

Is this related to https://github.com/scverse/spatialdata/issues/496?

ArneDefauw avatar Mar 21 '24 14:03 ArneDefauw

Hi, thanks for reporting. Yes it is related to the bug you mentioned. I will fix this over the weekend before the next release. You can call the internal functions that we use when calling write() for the moment. Sorry for the inconvenience.

LucaMarconato avatar Mar 21 '24 15:03 LucaMarconato

@LucaMarconato bump

melonora avatar Apr 15 '24 13:04 melonora