-
Notifications
You must be signed in to change notification settings - Fork 68
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
Regression in converting ordered factors R → Python (pandas) #1010
Comments
Relevant code: R → pandas rpy2/rpy2/robjects/pandas2ri.py Lines 331 to 352 in 5dc1885
Looking at NEWS:
Could it be related? I do not see anything obvious in blame view. pandas → R (this works, just for context): rpy2/rpy2/robjects/pandas2ri.py Lines 89 to 102 in 5dc1885
|
This seems like a regression is the R magic's default converter. In [22]: conv = robjects.default_converter+pandas2ri.converter
In [23]: %%R -o foo -c conv
...: foo <- ordered(c('a', 'b'))
...:
...:
In [24]: foo
Out[24]:
['a', 'b']
Categories (2, object): ['a' < 'b'] |
Confirmed. The R magic converter is mostly identical to cell 43 below. In [40]: with robjects.default_converter.context():
...: print(type(robjects.r("ordered(c('a', 'b'))")))
...:
<class 'rpy2.robjects.vectors.FactorVector'>
In [41]: import rpy2.robjects.numpy2ri as numpy2ri
In [42]: with (robjects.default_converter + numpy2ri.converter).context():
...: print(type(robjects.r("ordered(c('a', 'b'))")))
...:
<class 'numpy.ndarray'>
In [43]: with (robjects.default_converter + numpy2ri.converter + pandas2ri.converter).context():
...: print(type(robjects.r("ordered(c('a', 'b'))")))
...:
<class 'numpy.ndarray'> |
I asked a question here on the merged branch but it appears to have not been picked up. Please pardon the cross posting. |
Describe the issue or bug
Using pandas 1.5.x
rpy2 3.4.5:
rpy2 3.5.0 and 3.5.10:
Conversion the other way works fine (although there is no conversion rule for standalone
Categorical
object which would be a nice improvement):To Reproduce
ipython
from command line (or a Jupyter notebook with ipykernel)Expected behavior
Ordered factor gets converted to ordered categorical, not to numpy array with codes only.
Error
None
Additional context
The text was updated successfully, but these errors were encountered: