diff --git a/anndata/experimental/read_remote/read_remote.py b/anndata/experimental/read_remote/read_remote.py index f1d7d73c7..045e3bd83 100644 --- a/anndata/experimental/read_remote/read_remote.py +++ b/anndata/experimental/read_remote/read_remote.py @@ -66,16 +66,17 @@ def to_df(self) -> pd.DataFrame: """Convert to pandas dataframe.""" df = pd.DataFrame(index=self.dim_names) for key in self.keys(): - z = self[key] - if isinstance(z, zarr.Group) and "codes" in z: # catrgoricql - value = pd.Categorical.from_codes( - codes=read_elem(z["codes"]), - categories=read_elem(z["categories"]), - ordered=bool(_read_attr(z.attrs, "ordered")), - ) - else: - value = z[()] - df[key] = value + if "index" not in key: + z = self[key] + if isinstance(z, zarr.Group) and "codes" in z: # catrgoricql + value = pd.Categorical.from_codes( + codes=read_elem(z["codes"]), + categories=read_elem(z["categories"]), + ordered=bool(_read_attr(z.attrs, "ordered")), + ) + else: + value = z[()] + df[key] = value return df @property diff --git a/anndata/tests/test_read_remote.py b/anndata/tests/test_read_remote.py index 56511a0ff..1f8c97dec 100644 --- a/anndata/tests/test_read_remote.py +++ b/anndata/tests/test_read_remote.py @@ -77,3 +77,15 @@ def test_read_write_X(tmp_path, mtx_format): # remote.write_zarr(remote_pth) # need to implement writing! assert np.all(asarray(orig.X) == asarray(remote.X)) + assert (orig.obs == remote.obs.to_df()).all().all() + assert (orig.var == remote.var.to_df()).all().all() + + +def test_read_write_full(adata, tmp_path): + base_pth = Path(tmp_path) + orig_pth = base_pth / "orig.zarr" + adata.write_zarr(orig_pth) + remote = read_remote(orig_pth) + assert np.all(asarray(adata.X) == asarray(remote.X)) + assert (adata.obs == remote.obs.to_df()).all().all() + assert (adata.var == remote.var.to_df()).all().all()