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

LIU-207 expose buffer protocol getter for data drops #82

Merged
merged 1 commit into from
Nov 25, 2021
Merged

Conversation

calgray
Copy link
Collaborator

@calgray calgray commented Nov 24, 2021

Numerous python libraries accept the buffer protocol for reading in-memory data (in some cases with zero copy). This change adds the buffer() getter that is used by nifty gridder for reading .npy format data. e.g.

def drop_to_numpy(drop) -> np.ndarray:
    bio = drop.getIO()
    bio.open(OpenMode.OPEN_READ)
    buf = bio.buffer()
    res = np.load(io.BytesIO(buf))
    bio.close()
    return res

def numpy_to_drop(array: np.ndarray, drop):
    buf = io.BytesIO()
    np.save(buf, array)
    drop.write(buf.getbuffer())

@coveralls
Copy link

coveralls commented Nov 24, 2021

Coverage Status

Coverage decreased (-0.008%) to 78.343% when pulling b80c5b9 on liu-207 into 7b3be1a on master.

@awicenec
Copy link
Contributor

Easy change and seems quite useful. Thanks.

@awicenec awicenec merged commit 70a1d13 into master Nov 25, 2021
@awicenec awicenec deleted the liu-207 branch November 25, 2021 09:16
awicenec added a commit that referenced this pull request May 19, 2022
LIU-207 expose buffer protocol getter for data drops
pritchardn pushed a commit that referenced this pull request May 20, 2022
LIU-207 expose buffer protocol getter for data drops
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.

3 participants