summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorMircea Akos Bruma <bruma.mircea.a@gmail.com>2018-11-06 12:17:23 +0100
committerMircea Akos Bruma <bruma.mircea.a@gmail.com>2018-11-06 12:17:23 +0100
commit9ca7cb17cabd2996b17d25357cbc00b41985b58e (patch)
tree2d8b6b4cb0dfb2c79323e7cc92fdd56f8acff173 /numpy/core
parent97df928718a46b869d0d6675ffd6e8c539f32773 (diff)
downloadnumpy-9ca7cb17cabd2996b17d25357cbc00b41985b58e.tar.gz
BUG: Fix for np.dtype(ctypes.Structure) does not respect _pack_ field
See #10532
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/_dtype_ctypes.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/numpy/core/_dtype_ctypes.py b/numpy/core/_dtype_ctypes.py
index f10b4e99f..e6e675e2c 100644
--- a/numpy/core/_dtype_ctypes.py
+++ b/numpy/core/_dtype_ctypes.py
@@ -33,17 +33,28 @@ def _from_ctypes_array(t):
def _from_ctypes_structure(t):
- # TODO: gh-10533, gh-10532
- fields = []
- for item in t._fields_:
- if len(item) > 2:
- raise TypeError(
+ # TODO: gh-10533
+ if hasattr(t,"_pack_"):
+ fields = {}
+ for item in t._fields_:
+ if len(item) > 2:
+ raise TypeError(
"ctypes bitfields have no dtype equivalent")
- fname, ftyp = item
- fields.append((fname, dtype_from_ctypes_type(ftyp)))
+ fname, ftyp = item
+ fields[fname] = dtype_from_ctypes_type(ftyp), t._pack_
- # by default, ctypes structs are aligned
- return np.dtype(fields, align=True)
+ return np.dtype(fields, align=False)
+ else:
+ fields = []
+ for item in t._fields_:
+ if len(item) > 2:
+ raise TypeError(
+ "ctypes bitfields have no dtype equivalent")
+ fname, ftyp = item
+ fields.append((fname, dtype_from_ctypes_type(ftyp)))
+
+ # by default, ctypes structs are aligned
+ return np.dtype(fields, align=True)
def dtype_from_ctypes_type(t):