Skip to content

PEP 3118 - Simple data types format information lost #10265

@vanossj

Description

@vanossj

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions