1. rpy2
  2. rpy2
  3. rpy2
  4. Issues

Issues

Issue #398 new

Pandas2ri conversion does not work for ordered categories

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/pandas2ri.py:57: 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/utilization.py", line 153, in <module>
    plot(args.f[0])
  File "../../../../../ohua-stats/src/python/utilization.py", line 115, in plot
    pandas2ri.py2ri_categoryseries(data['funcid'])
  File "/Library/Python/2.7/site-packages/rpy2/robjects/pandas2ri.py", 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 (3)

  1. Log in to comment