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

reticulate 1.36 breaks anndata R #28

Closed
KaiWaldrant opened this issue Apr 18, 2024 · 4 comments
Closed

reticulate 1.36 breaks anndata R #28

KaiWaldrant opened this issue Apr 18, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@KaiWaldrant
Copy link

KaiWaldrant commented Apr 18, 2024

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

@rcannood
Copy link
Member

rcannood commented Apr 18, 2024

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"

@rcannood rcannood self-assigned this Apr 18, 2024
@rcannood rcannood added the bug Something isn't working label Apr 18, 2024
@rcannood
Copy link
Member

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

@rcannood
Copy link
Member

rcannood commented Apr 18, 2024

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").

@rcannood
Copy link
Member

rcannood commented Jul 8, 2024

Fixed in reticulate 1.36.1

@rcannood rcannood closed this as completed Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants