Skip to content

ValueError: Unknown dtype dtype('uint16') cannot be converted to ?gRMatrix. #111

@nroak

Description

@nroak

I'm encountering error below while saving the AnnData object in the R environment in this step of the tutorial.

> ro.globalenv["adata"] = adata

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[58], line 1
----> 1 ro.globalenv["adata"] = adata

File ~/opt/anaconda3/envs/velocyto/lib/python3.10/site-packages/rpy2/robjects/environments.py:35, in Environment.__setitem__(self, item, value)
     34 def __setitem__(self, item: str, value: typing.Any) -> None:
---> 35     robj = conversion.get_conversion().py2rpy(value)
     36     super(Environment, self).__setitem__(item, robj)

File ~/opt/anaconda3/envs/velocyto/lib/python3.10/functools.py:889, in singledispatch.<locals>.wrapper(*args, **kw)
    885 if not args:
    886     raise TypeError(f'{funcname} requires at least '
    887                     '1 positional argument')
--> 889 return dispatch(args[0].__class__)(*args, **kw)

File ~/opt/anaconda3/envs/velocyto/lib/python3.10/site-packages/anndata2ri/py2r.py:56, in py2rpy_anndata(obj)
     54 # TODO: sparse
     55 x = {} if obj.X is None else dict(X=mat_converter.py2rpy(obj.X.T))
---> 56 layers = {k: mat_converter.py2rpy(v.T) for k, v in obj.layers.items()}
     57 assays = ListVector({**x, **layers})
     59 row_args = {k: pandas2ri.py2rpy(v) for k, v in obj.var.items()}

File ~/opt/anaconda3/envs/velocyto/lib/python3.10/site-packages/anndata2ri/py2r.py:56, in <dictcomp>(.0)
     54 # TODO: sparse
     55 x = {} if obj.X is None else dict(X=mat_converter.py2rpy(obj.X.T))
---> 56 layers = {k: mat_converter.py2rpy(v.T) for k, v in obj.layers.items()}
     57 assays = ListVector({**x, **layers})
     59 row_args = {k: pandas2ri.py2rpy(v) for k, v in obj.var.items()}

File ~/opt/anaconda3/envs/velocyto/lib/python3.10/functools.py:889, in singledispatch.<locals>.wrapper(*args, **kw)
    885 if not args:
    886     raise TypeError(f'{funcname} requires at least '
    887                     '1 positional argument')
--> 889 return dispatch(args[0].__class__)(*args, **kw)

File ~/opt/anaconda3/envs/velocyto/lib/python3.10/site-packages/anndata2ri/scipy2ri/py2r.py:88, in py2r_context.<locals>.wrapper(obj)
     36     importr('Matrix')  # make class available
     37     matrix = SignatureTranslatedAnonymousPackage(
     38         """
     39         sparse_matrix <- function(x, conv_data, dims, ...) {
   (...)
     85         'matrix',
     86     )
---> 88 return f(obj)

File ~/opt/anaconda3/envs/velocyto/lib/python3.10/site-packages/anndata2ri/scipy2ri/py2r.py:97, in csc_to_rmat(csc)
     93 @converter.py2rpy.register(sparse.csc_matrix)
     94 @py2r_context
     95 def csc_to_rmat(csc: sparse.csc_matrix):
     96     csc.sort_indices()
---> 97     conv_data = get_type_conv(csc.dtype)
     98     with localconverter(default_converter + numpy2ri.converter):
     99         return matrix.from_csc(i=csc.indices, p=csc.indptr, x=csc.data, dims=list(csc.shape), conv_data=conv_data)

File ~/opt/anaconda3/envs/velocyto/lib/python3.10/site-packages/anndata2ri/scipy2ri/py2r.py:28, in get_type_conv(dtype)
     26     return base.as_logical
     27 else:
---> 28     raise ValueError(f'Unknown dtype {dtype!r} cannot be converted to ?gRMatrix.')

ValueError: Unknown dtype dtype('uint16') cannot be converted to ?gRMatrix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions