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

Custom conversion function no longer works with reticulate >= 1.36.0 #1613

Closed
lazappi opened this issue May 27, 2024 · 4 comments · Fixed by #1614
Closed

Custom conversion function no longer works with reticulate >= 1.36.0 #1613

lazappi opened this issue May 27, 2024 · 4 comments · Fixed by #1614

Comments

@lazappi
Copy link

lazappi commented May 27, 2024

Hi

In the {zellkonverter} Bioconductor package we have some custom Python to R conversion functions. One of these that is designed to handle numpy recarray's (array type 20) no longer works with {reticulate} >= 1.36.0.

Here is a small example (there is probably a nicer way to write this but this works):

library(zellkonverter)

reticulate::py_run_string("import numpy as np", convert = FALSE)
reticulate::py_run_string(
    "array = np.array([(1.0, 2), (3.0, 4)], dtype=[('x', float), ('y', int)])",
    convert = FALSE
)
result <- reticulate::py_run_string("rec_array = array.view(np.recarray)", convert = FALSE)

reticulate::py_to_r(result$rec_array)
# With reticulate <= 1.35.0 this works
#> [,1] [,2]
#> [1,]    1    2
#> [2,]    3    4

# With reticulate >= 1.36.0 there is an error
#> Error: Conversion from numpy array type 20 is not supported

As far as I can tell, the custom conversion function is not being called at all. It seems like there were some fairly major changes with v1.36.0 so if you have any advice on what might be causing this change and how to address it that would be great. Or if there is an alternative/better way to handle converting these arrays that would also be helpful.

Thanks!

@t-kalinowski
Copy link
Member

t-kalinowski commented May 28, 2024

Thanks for reporting! This is fixed on main now.

By the way, I noticed that numpy recarrays inherit from S3 class numpy.recarray. It may make sense to narrow the registered S3 method from numpy.ndarray to numpy.recarray.

@lazappi
Copy link
Author

lazappi commented May 29, 2024

Thanks for reporting! This is fixed on main now.

Thanks! Do know when it might reach CRAN?

By the way, I noticed that numpy recarrays inherit from S3 class numpy.recarray. It may make sense to narrow the registered S3 method from numpy.ndarray to numpy.recarray.

Ok. I think that wasn't the case when I wrote this originally but I'll check again. Thanks for the tip.

@t-kalinowski
Copy link
Member

t-kalinowski commented May 29, 2024

We just submitted a new release to CRAN last week (May 21). CRAN policy states that updates should be “no more than every 1–2 months”. Adhering to the CRAN policy, the soonest next update would be ~ June 21. However, occasionally, we do a rapid release in violation of the CRAN policy if circumstances warrant it.

I think this regression has been live on CRAN for ~50 days already (since Reticulate 1.36). How impactful would another 20 days be?

@lazappi
Copy link
Author

lazappi commented May 31, 2024

I think that should be fine in this case as there is a fairly easy workaround by getting people to install v1.35.0/devel if needed. Thanks!

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

Successfully merging a pull request may close this issue.

2 participants