-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Unexpected error when __sizeof__
is malformed when running Python
#13491
Comments
Related: #11543 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions. |
This issue has been automatically closed due to inactivity. |
I believe the issue is still not solved (bumping it for the bot) |
Any thoughts on what the right solution here is? Do we need to catch errors when invoking sizeof and return 0 or NA on error, or something similar? Or is there a way to get the "internal" size of an object, bypassing any dunder methods defined for the class? |
I don't know of another way. What do we use The only other way I think of is to setup error handlers: last_error <- reticulate::py_last_error()
size <- tryCatch(
sys$getsizeof(object),
python.builtin.BaseException = function(e) {
reticulate::py_last_error(last_error) # restore previous exception
NA_integer_
}) |
I think the size here is just for reporting a size in the Environment pane, so it's probably fine for that to be unknown / NA if we couldn't compute it. (Reporting the object size in Python is perilous anyhow, given that objects can be shared...) |
Could it be related to a bug in the AnnData Python package instead? If the unexpected behaviour is only present when subsetting using this package (see #1332 |
In that case, if the bug is so rare it only applies to AnnData in practice, then perhaps the fix is to advise users to call: reticulate:::py_register_load_hook("anndata", function() {
reticulate::py_run_string(local = TRUE, r"---(
import anndata
anndata.AnnData.__sizeof__ = lambda: -2147483648 # R NA_integer_
)---")
}) ( and suggest a PR to AnnData ) |
I think I agree with that. I imagine the implicit contract in |
@t-kalinowski do you mind commenting on their repo given your knowledge of the problem space here? |
@jthomasmock, It looks like this has already been fixed upstream: rstudio/reticulate#1332 (comment) |
System details
Steps to reproduce the problem
Execute the folling in the reticulate repl:
Once
obj
is created we get an error:Describe the problem in detail
Once
obj
is defined, the IDE is triggered to call.rs.reticulate.describeObject
which tries to obtain the object size via:rstudio/src/cpp/session/modules/SessionReticulate.R
Lines 1618 to 1620 in cfeca70
sys.getsizeof
calls the__sizeof__
that can raise errors.Describe the behavior you expected
Unless the user explicitly calls
sys.getsizeof()
we shouldn't expose the error to the user.The text was updated successfully, but these errors were encountered: