pandas.Series Change breaks rpy2

Issue #173 resolved
janschulz created an issue

pandas did some refactoring of Series and it seems that this breaks rpy2:

Bugreport with Exception: https://github.com/pydata/pandas/issues/5698

Infos about the refactoring of Series: http://pandas.pydata.org/pandas-docs/dev/whatsnew.html#internal-refactoring

Comments (15)

  1. Jeffrey Tratner

    I'm planning to create a script to test packages that depend on pandas so we can catch these issues earlier. If this is exercised by rpy2's test suite (or you can add a test for it), I can try to add rpy2 to the script.

  2. janschulz reporter

    a working patch (which works against latest pandas) seems to be this:

    --- rpy2\robjects\numpy2ri.py   Fri Dec 20 17:35:43 2013
    +++ rpy2\robjects\numpy2ri.py.new   Fri Dec 20 17:42:42 2013
    @@ -3,6 +3,7 @@
     import rpy2.rinterface as rinterface
     from rpy2.rinterface import SexpVector, INTSXP
     import numpy
    +import pandas
    
     from rpy2.robjects.vectors import DataFrame, Vector, ListVector
    
    @@ -26,7 +27,7 @@
     def numpy2ri(o):
         """ Augmented conversion function, converting numpy arrays into
         rpy2.rinterface-level R structures. """
    -    if isinstance(o, numpy.ndarray):
    +    if isinstance(o, (numpy.ndarray, pandas.Series)):
             if not o.dtype.isnative:
                 raise(ValueError("Cannot pass numpy arrays with non-native byte orders at the moment."))
    

    See also the discussion in the above pandas bugreport: https://github.com/pydata/pandas/issues/5698

  3. Laurent Gautier

    Thanks for the report and everyone's participation.

    Make sure to work things against the branch "version_2.4.x".Support for pandas in the 2.3.x series of rpy2 is partial.

    Also, a pull request is easier to process than a path copy/pasted in a comment.

  4. janschulz reporter

    Sorry, after trying to figure out how to get hg running on Windows, finally installing TortoiseHG and then trying to figure out how to configure it to use my default ssh key which bitbucket nicely imported from github, I simple gave up. It would be nice if someone with a linux system and all apps configured could do this.

  5. janschulz reporter

    damn it, that was against the wrong branch. I have no idea how to change this, sorry.

    Now it's a one line change:

    @@ -41,7 +41,7 @@
     def numpy2ri(o):
         """ Augmented conversion function, converting numpy arrays into
         rpy2.rinterface-level R structures. """
    -    if isinstance(o, numpy.ndarray):
    +    if hasattr(o, "__array__"):
             if not o.dtype.isnative:
                 raise(ValueError("Cannot pass numpy arrays with non-native byte orders at the moment."))
    

    If someone else wants to touch hg: feel free. I won't :-/

  6. Laurent Gautier

    @janschulz The rpy2 repository is temporarily in an unusual state. The "default" branch, that used to be for version 2.4.0, is currently broken.

    I do not not how things are done with TortoiseHG, but on the command line one can switch branches with:
    hg branch version_2.4.x

    Once you have made changes, testing them could be done easily on drone.io.

    You can use your existing bitbucket account to log in (no need to create a new account), and create a new project (button "New Project" on the top menu). Link that new project to your fork of rpy2 and simply add the following in the text area "Commands" (in Section "Builds & Tests").

    bash scripts/test_drone.io.sh.
    
  7. janschulz reporter

    How would you you rebase on top of the 2.4/2.3 branch? Or is that already taken care of?

  8. Jeffrey Tratner

    I wouldn't bother rebasing... it is only one line, might be easier to
    delete and then force push a new one

  9. Laurent Gautier

    @janschulz I missed that you were using Windows. While rpy2 can still build with it, getting the toolchain right is a bit of a trouble. If your main OS is Windows, running Linux in a VM might be the easiest path.

  10. Laurent Gautier

    @janschulz, @jtratner A main difference with Mercurial (when compared to Git) is that history is indelible.

  11. Laurent Gautier

    Thanks. I merged the pull request 24 (and grafted it to branch_2.4.x as well). A bugfix release rpy2-2.3.9 should be out soon.

  12. Log in to comment