[Numpy-svn] r6529 - in trunk/numpy/core: . tests

numpy-svn at scipy.org numpy-svn at scipy.org
Mon Mar 2 10:08:32 EST 2009


Author: cdavid
Date: 2009-03-02 09:08:27 -0600 (Mon, 02 Mar 2009)
New Revision: 6529

Modified:
   trunk/numpy/core/defchararray.py
   trunk/numpy/core/tests/test_defchararray.py
Log:
Allow c in dtype for charray (#917).

Modified: trunk/numpy/core/defchararray.py
===================================================================
--- trunk/numpy/core/defchararray.py	2009-03-02 15:01:21 UTC (rev 6528)
+++ trunk/numpy/core/defchararray.py	2009-03-02 15:08:27 UTC (rev 6529)
@@ -53,7 +53,7 @@
 
     def __array_finalize__(self, obj):
         # The b is a special case because it is used for reconstructing.
-        if not _globalvar and self.dtype.char not in 'SUb':
+        if not _globalvar and self.dtype.char not in 'SUbc':
             raise ValueError, "Can only create a chararray from string data."
 
     def __getitem__(self, obj):

Modified: trunk/numpy/core/tests/test_defchararray.py
===================================================================
--- trunk/numpy/core/tests/test_defchararray.py	2009-03-02 15:01:21 UTC (rev 6528)
+++ trunk/numpy/core/tests/test_defchararray.py	2009-03-02 15:08:27 UTC (rev 6529)
@@ -23,6 +23,15 @@
         assert all(self.A == self.B)
 
 
+class TestChar(TestCase):
+    def setUp(self):
+        self.A = np.array('abc1', dtype='c').view(np.chararray)
+
+    def test_it(self):
+        assert self.A.shape == (4,)
+        assert self.A.upper()[:2].tostring() == 'AB'    
+
+
 class TestOperations(TestCase):
     def setUp(self):
         self.A = np.array([['abc', '123'],




More information about the Numpy-svn mailing list