Closed KaiWaldrant closed 4 months ago
Thanks for reporting this! Here is a minimum reproducible example:
library(anndata)
ad <- AnnData(
X = matrix(0:5, nrow = 2),
obs = data.frame(group = c("a", "b"), row.names = c("s1", "s2")),
var = data.frame(type = c(1L, 2L, 3L), row.names = c("var1", "var2", "var3")),
layers = list(
spliced = matrix(4:9, nrow = 2),
unspliced = matrix(8:13, nrow = 2)
)
)
adpy <- ad$.__enclos_env__$private$.anndata
adpy$obs
# group
# s1 a
# s2 b
reticulate::py_to_r(adpy$obs)
# Error: Expected a python object, received a character
class(adpy$obs)
# [1] "pandas.core.frame.DataFrame" "pandas.core.generic.NDFrame" "pandas.core.base.PandasObject" "pandas.core.accessor.DirNamesMixin"
# [5] "pandas.core.indexing.IndexingMixin" "pandas.core.arraylike.OpsMixin" "python.builtin.object"
Here's an even smaller example:
library(reticulate)
df <- data.frame(
row.names = c("s1", "s2"),
group = c("a", "b")
)
py_to_r(r_to_py(df)) # works
# group
# s1 a
# s2 b
library(anndata)
py_to_r(r_to_py(df))
# Error: Expected a python object, received a character
This issue was fixed by rstudio/reticulate#1592 and will be included in the next release of reticulate.
For the time being, users encountering this issue can switch to the latest version of reticulate by running install.packages("devtools"); devtools::install_github("rstudio/reticulate")
or install.packages("pkg"); pkg::pkg_install("rstudio/reticulate")
.
Fixed in reticulate 1.36.1
Anndata throws an error when trying to access for example
.obs
:Error: Expected a python object, received a character
Might be related to rstudio/reticulate#1531