-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
PEP 3118 - Simple data types format information lost #10265
Copy link
Copy link
Closed
Labels
Description
When creating basic data types, their Py_buffer always shows the data as an array of bytes. PEP 3118 suggests that these should have ndim=0 and the correct format string in the Py_buffer structure.
Example
np_f = np.float32(75.3)
np_f.ndim
>>> 0 # makes sense, matches PEP3118
mem_np_f = memoryview(np_f)
# memoryview, accesses np_f via its Py_buffer interface
mem_np_f.ndim
>>> 1 # expect 0
mem_np_f.shape
>>> (4, ) # expect ()
mem_np_f.format
>>> 'B' # expect "f"ctypes Py_buffer interface retains type information for simple types
f = ctypes.c_float(75.3)
mem_f = memoryview(f)
mem_f.ndim
>>> 0
mem_f.shape
>>> ()
mem_f.format
>>> '<f'Example from:
Windows 10 and Linux
Python 3.5.1
numpy 1.10.1
Reactions are currently unavailable