summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/_internal.py12
-rw-r--r--numpy/core/tests/test_multiarray.py5
2 files changed, 11 insertions, 6 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index 74df9b926..d7f1a1119 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -454,10 +454,10 @@ def _dtype_from_pep3118(spec, byteorder='@', is_subdtype=False):
# 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 @@ def _dtype_from_pep3118(spec, byteorder='@', is_subdtype=False):
# 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
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index af251816a..3a3fefd9b 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -1624,5 +1624,10 @@ if sys.version_info >= (2, 6):
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()