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

Failed ri2py conversion of Vectors.ListVector object to Python dictionary #13018

Closed
ParfaitG opened this issue Apr 28, 2016 · 10 comments
Closed

Comments

@ParfaitG
Copy link
Contributor

Current conversion of R objects into Python usng pandas2ri.ri2py does not work for the <class 'rpy2.robjects.vectors.ListVector'> object. As noted here, pandas2ri.py2ri() and pandas2ri.ri2py() are current methods to handle conversion. However, previous deprecated com.convert_robj() correctly converts the R object to Python dictionary:

import rpy2
from rpy2.robjects.numpy2ri import numpy2ri
from rpy2.robjects.packages import importr
import numpy as np

# FISHER EXACT TEST EXAMPLE
cont = np.reshape(np.arange(0,4), (2,2))  
statspackage = importr('stats',  robject_translations={'format_perc': '_format_perc'})
result = statspackage.fisher_test(numpy2ri(cont), simulate_p_value = True, B = 100)

# DEPRECATED CONVERSION
import pandas.rpy.common as com
pyresultdict = com.convert_robj(result)

print(type(pyresultdict))   # PYTHON DICTIONARY TYPE

# CURRENT CONVERSION
from rpy2.robjects import pandas2ri
pandas2ri.activate()
pyresultdict = pandas2ri.ri2py(result)

print(type(pyresultdict))   # REMAINS R LISTVECTOR TYPE
# Expected Output
<class 'dict'>
<class 'dict'>
# output of rpy2.__version__
2.5.4

# output of  pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.4.1.final.0
python-bits: 64
OS: Windows
OS-release: 8
machine: AMD64
processor: Intel64 Family 6 Model 37 Stepping 2, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.18.0
nose: None
pip: 8.1.0
setuptools: 2.1
Cython: None
numpy: 1.10.4
scipy: 0.17.0
...

@jreback
Copy link
Contributor

jreback commented Apr 28, 2016

rpy2 is supported directly http://rpy.sourceforge.net/rpy2/doc-2.5/html/overview.html

not in pandas any longer

@ParfaitG
Copy link
Contributor Author

ParfaitG commented Apr 28, 2016

Interestingly the pandas 0.18 rpy2 page pointed me here to report Issues. See link in second Warning box. Please have the Pandas team update page accordingly.

@jreback
Copy link
Contributor

jreback commented Apr 28, 2016

you can do a PR if you want

@ParfaitG
Copy link
Contributor Author

Forgive me - please advise what "PR" means and how to do it on GitHub.

@jreback
Copy link
Contributor

jreback commented Apr 28, 2016

http://pandas.pydata.org/pandas-docs/stable/contributing.html

you might be able to submit this directly using github as this is just a doc-change.
as opposed to fokring & cloning the repo and submitting

@lgautier
Copy link
Contributor

FWIW rpy2's doc has moved to readthedoc some time ago: http://rpy2.readthedocs.io/

@ParfaitG
Copy link
Contributor Author

Thanks @lgautier. The pandas team may want to add the link to their rpy2 page.

@jreback
Copy link
Contributor

jreback commented Apr 30, 2016

thanks @lgautier updated for 0.18.1 release (soon)

@jorisvandenbossche jorisvandenbossche added this to the No action milestone Jan 16, 2017
@jorisvandenbossche
Copy link
Member

@ParfaitG Late reply, but I think your question above on how to convert such a ListVector as in your example is a very valid question. As we are going to remove pandas.rpy from pandas, can you report this either on the rpy2 issue tracker or raise concerns in the main issue: #9602

@lgautier
Copy link
Contributor

R's list objects are not constrained to unique names: several items in the list can have the same name.

I'd prefer to leave the conversion explicit (the user writes it in the his or her code and decides what to do if duplicates). I can provide a function that does it but throws an exception if duplicated.

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

No branches or pull requests

4 participants