Skip to content

Add support for numpy buffer format Zf and Zd #148675

@vstinner

Description

@vstinner
  • Python 3.14 added D and F formats to the ctypes and struct module
  • Python 3.15 adds D and F formats to the array module and to memoryview

The D and F formats were chosen for compatibility with numpy. Problem: in fact, numpy uses buffer formats Zd and Zf. Example:

>>> import numpy as np
>>> memoryview(np.array([1, 2, 3], dtype='F')).format
'Zf'
>>> memoryview(np.array([1, 2, 3], dtype='D')).format
'Zd'

So I propose adding support for Zd and Zf formats in array, ctypes, memoryview and struct. It requires changing the code expecting a single character to now accept a string (Zd and Zf have 2 characters!).

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions