-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support placeholder arrays in
ArrayModuleNumpyLike.frombuffer
(#…
…2693) * fix: make singletons trivially pickle-able * fix: support placeholders in `frombuffer` * test: add simple test --------- Co-authored-by: Jim Pivarski <jpivarski@users.noreply.github.com>
- Loading branch information
Showing
3 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE | ||
import pickle | ||
|
||
import numpy as np | ||
|
||
import awkward as ak | ||
from awkward._nplikes.numpy import Numpy | ||
from awkward.typetracer import PlaceholderArray | ||
|
||
nplike = Numpy.instance() | ||
|
||
|
||
def test_round_trip_placeholder(): | ||
layout = ak.contents.RecordArray( | ||
[ | ||
ak.contents.NumpyArray( | ||
PlaceholderArray(nplike, (4,), np.dtype(np.float64)) | ||
), | ||
ak.contents.NumpyArray([1, 2, 3, 4]), | ||
], | ||
["x", "y"], | ||
) | ||
|
||
form, length, container = ak.to_buffers(layout) | ||
result = ak.from_buffers(form, length, container, highlevel=False) | ||
|
||
assert isinstance(result.content("x").data, PlaceholderArray) | ||
|
||
assert result.content("x").data.shape == layout.content("x").data.shape | ||
assert result.content("x").data.dtype == layout.content("x").data.dtype | ||
|
||
|
||
def test_pickle_nplike(): | ||
assert pickle.loads(pickle.dumps(nplike)) is nplike |