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

numpy-svn@scip... numpy-svn@scip...
Sun Apr 4 15:20:40 CDT 2010


Author: ptvirtan
Date: 2010-04-04 15:20:40 -0500 (Sun, 04 Apr 2010)
New Revision: 8315

Modified:
   trunk/numpy/core/_internal.py
   trunk/numpy/core/tests/test_multiarray.py
Log:
BUG: core: fix bugs in PEP 3118 format string parsing

- Handle consecutive characters (eg. 'xxxx') properly
- Compute native padding correctly

Modified: trunk/numpy/core/_internal.py
===================================================================
--- trunk/numpy/core/_internal.py	2010-04-04 15:34:49 UTC (rev 8314)
+++ trunk/numpy/core/_internal.py	2010-04-04 20:20:40 UTC (rev 8315)
@@ -454,10 +454,10 @@
                 # Not supported
                 raise ValueError("Non item-size 1 structures not supported")
         elif spec[0] in type_map_chars:
-            j = 1
-            for j in xrange(1, len(spec)):
-                if spec[j] not in type_map_chars:
-                    break
+            if spec[0] == 'Z':
+                j = 2
+            else:
+                j = 1
             typechar = spec[:j]
             spec = spec[j:]
             is_padding = (typechar == 'x')
@@ -476,8 +476,8 @@
         #      that the start of the array is *also* aligned.
         extra_offset = 0
         if byteorder == '@':
-            start_padding = offset % value.alignment
-            intra_padding = value.itemsize % value.alignment
+            start_padding = (-offset) % value.alignment
+            intra_padding = (-value.itemsize) % value.alignment
 
             offset += start_padding
 

Modified: trunk/numpy/core/tests/test_multiarray.py
===================================================================
--- trunk/numpy/core/tests/test_multiarray.py	2010-04-04 15:34:49 UTC (rev 8314)
+++ trunk/numpy/core/tests/test_multiarray.py	2010-04-04 20:20:40 UTC (rev 8315)
@@ -1624,5 +1624,10 @@
             else:
                 assert_equal(y.format, '<i')
 
+        def test_padding(self):
+            for j in xrange(8):
+                x = np.array([(1,),(2,)], dtype={'f0': (int, j)})
+                self._check_roundtrip(x)
+
 if __name__ == "__main__":
     run_module_suite()



More information about the Numpy-svn mailing list