Patch.
diff -r 78fbb8a3131a rpy/rinterface/array.c
--- a/rpy/rinterface/array.c	Mon Feb 02 21:14:18 2009 +0100
+++ b/rpy/rinterface/array.c	Tue Feb 03 20:46:37 2009 -0800
@@ -36,7 +36,12 @@
     //case STRSXP: return 'S';
 	//FIXME: handle 'O' (as R list ?)
   case CPLXSXP: return 'c';
-  case LGLSXP: return 'b';
+  // It would be more logical (hah) to return 'b' here, but 1) R booleans are
+  // full integer width, and Numpy for example can only handle 8-bit booleans,
+  // not 32-bit, 2) R actually uses this width; NA_LOGICAL is the same as
+  // NA_INTEGER, i.e. INT_MIN, i.e. 0x80000000. So this also lets us preserve
+  // NA's:
+  case LGLSXP: return 'i';
   }
   return 0;
 }
diff -r 78fbb8a3131a rpy/rinterface/tests/test_SexpVectorNumeric.py
--- a/rpy/rinterface/tests/test_SexpVectorNumeric.py	Mon Feb 02 21:14:18 2009 +0100
+++ b/rpy/rinterface/tests/test_SexpVectorNumeric.py	Tue Feb 03 20:46:37 2009 -0800
@@ -47,6 +47,14 @@
     for orig, new in itertools.izip(px, nx):
         self.assertEquals(orig, new)
     
+def testArrayStructBoolean(self, numericModule):
+    px = [True, False, True]
+    x = rinterface.SexpVector(px, rinterface.LGLSXP)
+    nx = numericModule.asarray(x)
+    self.assertEquals('i', nx.typecode()) # not 'b', see comments in array.c
+    for orig, new in itertools.izip(px, nx):
+        self.assertEquals(orig, new)
+
 
 class SexpVectorNumericTestCase(unittest.TestCase):
 
@@ -60,16 +68,8 @@
     def testArrayStructNumpyComplex(self):
         testArrayStructComplex(self, numpy)
 
-
-
-#     def testArrayStructBoolean(self):
-#         px = [True, False, True]
-#         x = rinterface.SexpVector(px, rinterface.REALSXP)
-#         nx = Numeric.asarray(x)
-#         self.assertEquals('b', nx.typecode())
-#         for orig, new in itertools.izip(px, nx):
-#             self.assertEquals(orig, new)
-#         self.assertTrue(False)
+    def testArrayStructNumpyBoolean(self):
+        testArrayStructBoolean(self, numpy)
 
 def suite():
     suite = unittest.TestLoader().loadTestsFromTestCase(SexpVectorNumericTestCase)
------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to