Skip to content

[ENH] Support F-contiguous memoryviews in cast #91484

Open

Description

@jakirkham

Currently memoryview.cast requires C-contiguous data when going from N-D to 1-D. As a result F-contiguous data is not supported. Please see example below:

>>> mv.c_contiguous
False
>>> mv.f_contiguous
True
>>> mv.cast("B")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: memoryview: casts are restricted to C-contiguous views

However as F-contiguous data is still contiguous and can be viewed in 1-D, it seems possible to support this type of data as well. PickleBuffer's raw method does appear to support both C & F contiguous data. Building off the example above:

>>> from pickle import PickleBuffer
>>> pb = PickleBuffer(mv)
>>> pb.raw()
<memory at 0x1105cec70>

This would be useful when interacting with other libraries that work with this kind of data. That said, don't know if there is other context behind the C-contiguous constraint that I may be missing here.

Linked PRs

Activity

  1. self-assigned this
    on Oct 3, 2022
  2. corona10 commented on Nov 6, 2022

    @corona10
    Member

    I am working on this issue.

  3. jamie2779 commented on Aug 15, 2025

    @jamie2779
    Contributor

    @corona10 I'll try this issue

  4. added a commit that references this issue on Jul 24, 2026
  5. added a commit that references this issue on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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