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

Cannot use name 'pop' in Pandas DataFrame #244

Closed
ijlyttle opened this issue Apr 30, 2018 · 4 comments
Closed

Cannot use name 'pop' in Pandas DataFrame #244

ijlyttle opened this issue Apr 30, 2018 · 4 comments

Comments

@ijlyttle
Copy link

ijlyttle commented Apr 30, 2018

This may be related to #157

library("reticulate")

py_run_string("import pandas as pd")
py_run_string("df_bad = pd.DataFrame({'pop': ['foo']})")
py_run_string("df_good = pd.DataFrame({'apop': ['foo']})")

So far so good, but when I try to bring this into R:

py$df_bad
Error in py_get_attr_impl(x, name, silent) : 
  AttributeError: 'function' object has no attribute 'as_matrix'

However:

py$df_good
  apop
1  foo

It seems like the name 'pop' is somehow messing things up, and I don't think it should.

@AliciaSchep
Copy link
Contributor

In python, doing

df_bad.pop.as_matrix()

gives an error. This is because pop is a method of a DataFrame.

The following in python works:

df_bad[['pop']].as_matrix()

It seems like somewhere in reticulate's conversion df_bad.pop.as_matrix is getting called and if that could be avoided by calling df_bad[['pop']].as_matrix that would solve the issue... there are likely other DataFrame methods other than pop that will lead to this kind of unexpected error.

@ijlyttle
Copy link
Author

ijlyttle commented May 1, 2018

Nice catch, thanks!

@jjallaire
Copy link
Member

Assuming we can now close this?

@ijlyttle
Copy link
Author

ijlyttle commented May 3, 2018

Yes, 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

No branches or pull requests

3 participants