Skip to content

Add support for numpy buffer format Zf and Zd #148675

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

Activity

  1. added 2 commits that reference this issue on Apr 17, 2026
  2. vstinner commented on Apr 17, 2026

    @vstinner
    MemberAuthor

    This issue was escalated to the Steering Council: Decide buffer protocol format string for complex numbers.

  3. skirpichev commented on Apr 17, 2026

    @skirpichev
    Member

    The D and F formats were chosen for #132827. Problem: in fact, numpy uses buffer formats Zd and Zf.

    In fact, numpy uses both. So, 'F'/'D' codes does make sense for the ctypes module, at least. If SC approves the compatibility break - we can change buffer formats to Zd/Zf in the ctypes module.

    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!).

    I think it's better to revert changes for array and memoryview (#148674) and leave problem for a new champion, who will make a PEP with a proper extension of the struct format string for new types.

  4. added 2 commits that reference this issue on May 4, 2026
  5. added a commit that references this issue on May 4, 2026
  6. hugovk commented on May 4, 2026

    @hugovk
    Member

    Are we all done here for 3.15?

  7. encukou commented on May 5, 2026

    @encukou
    Member

    For b1, yes. The Steering Council will need to discuss this, later.

  8. 9 remaining items

  9. added 4 commits that reference this issue on May 13, 2026
  10. vstinner commented on May 18, 2026

    @vstinner
    MemberAuthor

    Add support for numpy buffer format Zf and Zd

    The initial issue has been implemented. For further work, please open new issue. I close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions