Revision: 637 http://rpy.svn.sourceforge.net/rpy/?rev=637&view=rev Author: lgautier Date: 2008-08-22 13:49:08 +0000 (Fri, 22 Aug 2008)
Log Message: ----------- Fixed handling of unicode and complex vectors Modified Paths: -------------- branches/rpy_nextgen/rpy/robjects/__init__.py branches/rpy_nextgen/rpy/robjects/tests/testRobjects.py Modified: branches/rpy_nextgen/rpy/robjects/__init__.py =================================================================== --- branches/rpy_nextgen/rpy/robjects/__init__.py 2008-08-20 14:09:47 UTC (rev 636) +++ branches/rpy_nextgen/rpy/robjects/__init__.py 2008-08-22 13:49:08 UTC (rev 637) @@ -54,7 +54,6 @@ res = RObject(o) return res -#FIXME: clean and nice mechanism to allow user-specified mapping function #FIXME: better names for the functions ri2py = default_ri2py @@ -87,8 +86,12 @@ res = rinterface.SexpVector([o, ], rinterface.REALSXP) elif isinstance(o, str): res = rinterface.SexpVector([o, ], rinterface.STRSXP) + elif isinstance(o, unicode): + res = rinterface.SexpVector([o, ], rinterface.STRSXP) elif isinstance(o, list): res = r.list(*[ri2py(py2ri(x)) for x in o]) + elif isinstance(o, complex): + res = rinterface.SexpVector([o, ], rinterface.CPLXSXP) else: raise(ValueError("Nothing can be done for the type %s at the moment." %(type(o)))) return res Modified: branches/rpy_nextgen/rpy/robjects/tests/testRobjects.py =================================================================== --- branches/rpy_nextgen/rpy/robjects/tests/testRobjects.py 2008-08-20 14:09:47 UTC (rev 636) +++ branches/rpy_nextgen/rpy/robjects/tests/testRobjects.py 2008-08-22 13:49:08 UTC (rev 637) @@ -67,6 +67,7 @@ py = 1 rob = robjects.default_py2ro(py) self.assertTrue(isinstance(rob, robjects.RVector)) + self.assertEquals(rinterface.INTSXP, rob.typeof()) def testMapperPy2R_boolean(self): py = True @@ -74,8 +75,33 @@ self.assertTrue(isinstance(rob, robjects.RVector)) self.assertEquals(rinterface.LGLSXP, rob.typeof()) + def testMapperPy2R_str(self): + py = 'houba' + rob = robjects.default_py2ro(py) + self.assertTrue(isinstance(rob, robjects.RVector)) + self.assertEquals(rinterface.STRSXP, rob.typeof()) + + def testMapperPy2R_unicode(self): + py = u'houba' + self.assertTrue(isinstance(py, unicode)) + rob = robjects.default_py2ro(py) + self.assertTrue(isinstance(rob, robjects.RVector)) + self.assertEquals(rinterface.STRSXP, rob.typeof()) #FIXME: more tests + def testMapperPy2R_float(self): + py = 1.0 + rob = robjects.default_py2ro(py) + self.assertTrue(isinstance(rob, robjects.RVector)) + self.assertEquals(rinterface.REALSXP, rob.typeof()) + + def testMapperPy2R_complex(self): + py = 1.0 + 2j + rob = robjects.default_py2ro(py) + self.assertTrue(isinstance(rob, robjects.RVector)) + self.assertEquals(rinterface.CPLXSXP, rob.typeof()) + + def testOverride_ri2py(self): class Density(object): def __init__(self, x): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list