Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Buffers to memoryviews #656

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jakirkham
Copy link
Member

When this was written in the code, Python's Buffer Protocol support was inconsistent across Python versions (specifically on Python 2.7). Since Python 2.7 reached EOL and it was dropped from Numcodecs, the Python Buffer Protocol support has become more consistent.

At this stage the memoryview object, which Cython also supports, does all the same things that Buffer would do for us. Plus it is builtin to the Python standard library. It behaves similarly in a lot of ways.

Given this, switch the code over to memoryviews internally and drop Buffer.


TODO:

  • Unit tests and/or doctests in docstrings
  • Tests pass locally
  • Docstrings and API docs for any new/modified user-facing classes and functions
  • Changes documented in docs/release.rst
  • Docs build locally
  • GitHub Actions CI passes
  • Test coverage to 100% (Codecov passes)

@jakirkham jakirkham force-pushed the use_mv branch 2 times, most recently from 923df20 to e7afaa2 Compare November 22, 2024 03:56
Copy link

codecov bot commented Nov 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.92%. Comparing base (86f5ce4) to head (0c823e2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #656   +/-   ##
=======================================
  Coverage   99.92%   99.92%           
=======================================
  Files          62       62           
  Lines        2721     2721           
=======================================
  Hits         2719     2719           
  Misses          2        2           
---- 🚨 Try these New Features:

@jakirkham jakirkham force-pushed the use_mv branch 2 times, most recently from 7255767 to 2a942ad Compare November 22, 2024 04:07
When this was written in the code, Python's Buffer Protocol support was
inconsistent across Python versions (specifically on Python 2.7). Since
Python 2.7 reached EOL and it was dropped from Numcodecs, the Python
Buffer Protocol support has become more consistent.

At this stage the `memoryview` object, which Cython also supports, does
all the same things that `Buffer` would do for us. Plus it is builtin to
the Python standard library. It behaves similarly in a lot of ways.

Given this, switch the code over to `memoryview`s internally and drop
`Buffer`.
@jakirkham
Copy link
Member Author

Planning to merge end of week if no comments

Copy link
Contributor

@rabernat rabernat left a comment

Choose a reason for hiding this comment

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

This seems like a great improvement. Thanks so much @jakirkham!

Unfortunately my Cython isn't really good enough to provide a useful review. But the tests pass! 😆 And we are reducing LoC and simplifying many functions. So seems like a great direction.

Someone who actually groks Cython should review this for real.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants