Skip to content

Add support for numpy buffer format Zf and Zd #148675

Closed

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
    interpreter-core
    on Apr 17, 2026
  2. added 2 commits that reference this issue on Apr 17, 2026
  3. vstinner commented on Apr 17, 2026

    @vstinner
    MemberAuthor

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

  4. 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.

  5. added
    type-feature
    on Apr 17, 2026
  6. added 2 commits that reference this issue on May 4, 2026
  7. added a commit that references this issue on May 4, 2026
  8. hugovk commented on May 4, 2026

    @hugovk
    Member

    Are we all done here for 3.15?

  9. encukou commented on May 5, 2026

    @encukou
    Member

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

  10. 9 remaining items

  11. added 4 commits that reference this issue on May 13, 2026
  12. 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-coretype-feature

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions