GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-146151: memoryview supports 'F' and 'D' format types (complex) by skirpichev · Pull Request #146241 · python/cpython

Conversation

@skirpichev

@skirpichev skirpichev commented Mar 21, 2026 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: Support complex (float/double) types in array.array and memoryview #146151

📚 Documentation preview 📚: https://cpython-previews--146241.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@skirpichev
pythongh-146151: memoryview supports 'F' and 'D' format types (complex)
94ee023
@skirpichev
skirpichev requested a review from AA-Turner as a code owner March 21, 2026 06:23
@bedevere-app bedevere-app Bot mentioned this pull request Mar 21, 2026
Support complex (float/double) types in array.array and memoryview #146151
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Mar 21, 2026
vstinner
vstinner reviewed Mar 25, 2026
View reviewed changes
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_memoryview.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

skirpichev and others added 3 commits March 26, 2026 02:35
@skirpichev @vstinner
Apply suggestions from code review
c94450e
Co-authored-by: Victor Stinner <[email protected]>
@skirpichev
Merge branch 'master' into support-complex-memoryview/146151
43e9b18
@skirpichev
address review: add complex test to test_compare_equal()
a728a1b
@skirpichev
skirpichev requested a review from vstinner March 26, 2026 00:11
vstinner
vstinner approved these changes Mar 26, 2026
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The implementation looks complete and well tested.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Objects/memoryobject.c
memcpy(ptr, &x, sizeof(x));
}
else {
float x[2] = {(float)c.real, (float)c.imag};

@vstinner vstinner Mar 26, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure of the behavior on underflow or overflow of the double to float cast, so I tested:

>>> import struct, sys
>>> data=struct.pack('F', 0.0) * 4
>>> m=memoryview(bytearray(data)).cast('F')
>>> m[0]=math.nextafter(0, 1)
>>> m[1]=sys.float_info.min
>>> m[2]=sys.float_info.max
>>> m[3]=float("nan")
>>> m.tolist()
[0j, 0j, (inf+0j), (nan+0j)]

I got the values that I expected. I suppose that these conversions are well specified by IEEE 754.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@skirpichev skirpichev Mar 26, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior here is same as for 'f' format, just component-wise, see PACK_SINGLE macro.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2026-03-21-08-11-58.gh-issue-146151.4-lhim.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Mar 26, 2026
@skirpichev @vstinner
Update Misc/NEWS.d/next/Core_and_Builtins/2026-03-21-08-11-58.gh-issu…
f83e88f
…e-146151.4-lhim.rst

Co-authored-by: Victor Stinner <[email protected]>
@vstinner
vstinner merged commit c68a194 into python:main Mar 26, 2026
51 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Mar 26, 2026
@vstinner

vstinner commented Mar 26, 2026

Copy link
Copy Markdown
Member

Merged, thanks for your contribution.

skirpichev reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@skirpichev
skirpichev deleted the support-complex-memoryview/146151 branch March 26, 2026 18:34
@pablogsal pablogsal mentioned this pull request Apr 4, 2026
gh-130273: Fix traceback color output with unicode characters #142529
Merged
@seberg seberg mentioned this pull request Apr 12, 2026
gh-146151: support for complex arrays in the array module #146237
Merged
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Apr 16, 2026
@skirpichev @vstinner @clin1234
pythongh-146151: memoryview supports 'F' and 'D' format types (comple…
6735afa
…x) (python#146241)

Co-authored-by: Victor Stinner <[email protected]>
@skirpichev skirpichev mentioned this pull request Apr 17, 2026
Decide buffer protocol format string for complex numbers python/steering-council#345
Closed
skirpichev added a commit to skirpichev/cpython that referenced this pull request Apr 17, 2026
@skirpichev
Revert "pythongh-146151: memoryview supports 'F' and 'D' format types…
760e2f0
… (complex) (python#146241)"

This reverts commit c68a194.
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@skirpichev @vstinner @ljfp
pythongh-146151: memoryview supports 'F' and 'D' format types (comple…
03415bd
…x) (python#146241)

Co-authored-by: Victor Stinner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@skirpichev @vstinner
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.