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
pandas2ri - added named-vector-to-pandas conversion #887
base: master
Are you sure you want to change the base?
pandas2ri - added named-vector-to-pandas conversion #887
Conversation
201d5d7
to
c5b18c5
Compare
Codecov Report
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. @@ Coverage Diff @@
## master #887 +/- ##
==========================================
+ Coverage 88.97% 89.03% +0.05%
==========================================
Files 39 39
Lines 6839 6848 +9
==========================================
+ Hits 6085 6097 +12
+ Misses 754 751 -3
... and 2 files with indirect coverage changes 📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today! |
Hi, thanks for the PR. A review is long due. I am unsure about whether R named vectors should not be converted to pandas data frames by default, even within the context of the Having that said, the current behavior in rpy2 does not seem predictable enough: import rpy2.robjects as ro
import rpy2.robjects.pandas2ri as pd2r
# First list.
rlist = ro.r('c(a=1, b=2, c=3)')
with (ro.default_converter + pd2r.converter).context() as cv:
pylist = cv.rpy2py(rlist)
pylist
# array([1., 2., 3.])
# Second list. The conversion is closer to what I would expect, with the exception of
# `b.x` and `b.y` instead of nesting 'x' and 'y' under 'b'.
rlist = ro.r('c(a=1, b=list(x=list(z=4), y=5), c=3)')
with (ro.default_converter + pd2r.converter).context() as cv:
pylist = cv.rpy2py(rlist
pylist
# o{'a': [1.], 'b.x': o{'z': [4.], }, 'b.y': [5.], 'c': [3.], } |
This PR adds conversions from R named vector to Pandas Series and R named matrix to Pandas DataFrame.
It resolves the issue I encountered while retrieving the fixed effect coefficients (named vector) from
lme4.fixef()
and CI matrices fromconfint()
functions.I have also added
test_ri2pandas_named_vector()
pytest function to test the changes.