Pandas2ri conversion does not work for ordered categories

Issue #398 resolved
Sebastian Ertel
created an issue

Hi Laurent,

When trying to convert a pandas data frame with an ordered categorical column then the following error pops up:

/Library/Python/2.7/site-packages/rpy2/robjects/ UserWarning: Error while trying to convert the column "mycolumn". Fall back to string conversion. The error is: function takes at most 1 argument (2 given)
  (name, str(e)))

The try-catch block in pandas2ri. py2ri_pandasdataframe does not allow to see the actual stacktrace to understand which function is meant here. But using pandas2ri.py2ri_categoryseries(df) one receives the complete error:

Traceback (most recent call last):
  File "../../../../../ohua-stats/src/python/", line 153, in <module>
  File "../../../../../ohua-stats/src/python/", line 115, in plot
  File "/Library/Python/2.7/site-packages/rpy2/robjects/", line 82, in py2ri_categoryseries
    res.rclass = StrSexpVector('ordered', 'factor')
TypeError: function takes at most 1 argument (2 given)

So in pandas2ri. py2ri_categoryseries you call a StrSexpVector constructor with 2 arguments in case the category is ordered. However, in rpy2/rinterface/_rinterface.c at Line 3557 you register a single-argument constructor only.

So in short, the second is missing :)

Cheers, Sebastian.

Comments (4)

  1. Log in to comment