-
Notifications
You must be signed in to change notification settings - Fork 327
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
should '$' and '[' behave differently for pandas DataFrames? #251
Comments
After a chat with @jjallaire, we agree that we should try to migrate the semantics such that:
We'll plan to issue a warning if the use of the |
I think another possibility would have been to make for (attr_name in attrs) print(py_obj[[attr_name]]) however I think it would be quite confusing to let for (attr_name in attrs) print(`$`(py_obj, attr_name)) |
With #1431 the ambiguity is solved with:
|
After taking a closer look, I see that The benefit of adding a library(reticulate)
py_run_string("import pandas as pd")
pdf <- py_eval('pd.DataFrame({"pop": [1], "abc": [2]})', convert = F)
pdf$pop
#> <bound method DataFrame.pop of pop abc
#> 0 1 2>
pdf@pop
#> <bound method DataFrame.pop of pop abc
#> 0 1 2>
pdf["pop"]
#> 0 1
#> Name: pop, dtype: int64
pdf[["pop"]]
#> 0 1
#> Name: pop, dtype: int64
pdf$abc
#> 0 2
#> Name: abc, dtype: int64
pdf@abc
#> 0 2
#> Name: abc, dtype: int64
pdf["abc"]
#> 0 2
#> Name: abc, dtype: int64
pdf[["abc"]]
#> 0 2
#> Name: abc, dtype: int64 Created on 2023-08-15 with reprex v2.0.2 |
E.g. in Python:
However, for Python objects exposed to R,
[[
attempts to first access attributes rather than columns:Should
[[
prefer accessing items rather than attributes for DataFrames?I believe a similar question exists for Python dictionaries, and other objects implementing
__getitem__
in general.The text was updated successfully, but these errors were encountered: