Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

centered_pca result cannot be saved in h5ad #108

Open
MUCDK opened this issue Sep 9, 2024 · 2 comments
Open

centered_pca result cannot be saved in h5ad #108

MUCDK opened this issue Sep 9, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@MUCDK
Copy link
Collaborator

MUCDK commented Sep 9, 2024

Description of feature

---------------------------------------------------------------------------
IORegistryError                           Traceback (most recent call last)
Cell In[138], line 3
      1 import os
----> 3 adata_train_1.write(os.path.join(output_dir, "adata_train_1.h5ad"))
      4 adata_test_1.write(os.path.join(output_dir, "adata_test_1.h5ad"))
      5 adata_ood_1.write(os.path.join(output_dir, "adata_ood_1.h5ad"))

File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_core/anndata.py:1929, in AnnData.write_h5ad(self, filename, compression, compression_opts, as_dense)
   1926 if filename is None:
   1927     filename = self.filename
-> 1929 write_h5ad(
   1930     Path(filename),
   1931     self,
   1932     compression=compression,
   1933     compression_opts=compression_opts,
   1934     as_dense=as_dense,
   1935 )
   1937 if self.isbacked:
   1938     self.file.filename = filename

File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/h5ad.py:107, in write_h5ad(filepath, adata, as_dense, dataset_kwargs, **kwargs)
    105 write_elem(f, "var", adata.var, dataset_kwargs=dataset_kwargs)
    106 write_elem(f, "obsm", dict(adata.obsm), dataset_kwargs=dataset_kwargs)
--> 107 write_elem(f, "varm", dict(adata.varm), dataset_kwargs=dataset_kwargs)
    108 write_elem(f, "obsp", dict(adata.obsp), dataset_kwargs=dataset_kwargs)
    109 write_elem(f, "varp", dict(adata.varp), dataset_kwargs=dataset_kwargs)

File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/specs/registry.py:359, in write_elem(store, k, elem, dataset_kwargs)
    335 def write_elem(
    336     store: GroupStorageType,
    337     k: str,
   (...)
    340     dataset_kwargs: Mapping[str, Any] = MappingProxyType({}),
    341 ) -> None:
    342     """
    343     Write an element to a storage group using anndata encoding.
    344 
   (...)
    357         E.g. for zarr this would be `chunks`, `compressor`.
    358     """
--> 359     Writer(_REGISTRY).write_elem(store, k, elem, dataset_kwargs=dataset_kwargs)

File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/utils.py:243, in report_write_key_on_error.<locals>.func_wrapper(*args, **kwargs)
    241     raise ValueError("No element found in args.")
    242 try:
--> 243     return func(*args, **kwargs)
    244 except Exception as e:
    245     path = _get_display_path(store)

File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/specs/registry.py:309, in Writer.write_elem(self, store, k, elem, dataset_kwargs, modifiers)
    303 write_func = partial(
    304     self.find_writer(dest_type, elem, modifiers),
    305     _writer=self,
    306 )
    308 if self.callback is None:
--> 309     return write_func(store, k, elem, dataset_kwargs=dataset_kwargs)
    310 return self.callback(
    311     write_func,
    312     store,
   (...)
    316     iospec=self.registry.get_spec(elem),
    317 )

File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/specs/registry.py:57, in write_spec.<locals>.decorator.<locals>.wrapper(g, k, *args, **kwargs)
     55 @wraps(func)
     56 def wrapper(g: GroupStorageType, k: str, *args, **kwargs):
---> 57     result = func(g, k, *args, **kwargs)
     58     g[k].attrs.setdefault("encoding-type", spec.encoding_type)
     59     g[k].attrs.setdefault("encoding-version", spec.encoding_version)

File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/specs/methods.py:312, in write_mapping(f, k, v, _writer, dataset_kwargs)
    310 g = f.require_group(k)
    311 for sub_k, sub_v in v.items():
--> 312     _writer.write_elem(g, sub_k, sub_v, dataset_kwargs=dataset_kwargs)

File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/utils.py:243, in report_write_key_on_error.<locals>.func_wrapper(*args, **kwargs)
    241     raise ValueError("No element found in args.")
    242 try:
--> 243     return func(*args, **kwargs)
    244 except Exception as e:
    245     path = _get_display_path(store)

File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/specs/registry.py:304, in Writer.write_elem(self, store, k, elem, dataset_kwargs, modifiers)
    300 elif k in store:
    301     del store[k]
    303 write_func = partial(
--> 304     self.find_writer(dest_type, elem, modifiers),
    305     _writer=self,
    306 )
    308 if self.callback is None:
    309     return write_func(store, k, elem, dataset_kwargs=dataset_kwargs)

File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/specs/registry.py:269, in Writer.find_writer(self, dest_type, elem, modifiers)
    267         return self.registry.get_writer(dest_type, pattern, modifiers)
    268 # Raises IORegistryError
--> 269 return self.registry.get_writer(dest_type, type(elem), modifiers)

File ~/mambaforge/envs/cfp/lib/python3.11/site-packages/anndata/_io/specs/registry.py:117, in IORegistry.get_writer(self, dest_type, src_type, modifiers)
    115     return self.write[(dest_type, src_type, modifiers)]
    116 else:
--> 117     raise IORegistryError._from_write_parts(dest_type, src_type, modifiers)

IORegistryError: No method registered for writing <class 'numpy.matrix'> into <class 'h5py._hl.group.Group'>
Error raised while writing key 'X_mean' of <class 'h5py._hl.group.Group'> to /varm

@MUCDK MUCDK added the enhancement New feature or request label Sep 9, 2024
@joschif
Copy link
Collaborator

joschif commented Feb 12, 2025

Should be fixed by now in #97

@joschif joschif closed this as completed Feb 12, 2025
@joschif joschif reopened this Feb 12, 2025
@joschif
Copy link
Collaborator

joschif commented Feb 12, 2025

sorry my mistake, might not be fixed actually, although I believe the conversion to np.array() should have fixed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants