Skip to content

Commit

Permalink
test: test records too
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Sep 5, 2023
1 parent 1f13ba1 commit 0af11a4
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions tests/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pickle

import awkward as ak
import numpy as np


def test_pickle_ak_array():
Expand All @@ -14,7 +15,44 @@ def test_pickle_ak_array():
assert ak.almost_equal(array, next_array)
assert array.layout.form == next_array.layout.form
assert buffers
assert np.shares_memory(
array.layout.content.data,
next_array.layout.content.data,
)
assert np.shares_memory(
array.layout.starts.data,
next_array.layout.starts.data,
)
assert np.shares_memory(
array.layout.stops.data,
next_array.layout.stops.data,
)


def identity(x):
return x
def test_pickle_ak_record():
buffers = []
record = ak.zip(
{"x": [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]}, depth_limit=1
)[2]
next_record = pickle.loads(
pickle.dumps(record, protocol=5, buffer_callback=buffers.append),
buffers=buffers,
)
assert record.layout.at == next_record.layout.at

array = ak.Array(record.layout.array)
next_array = ak.Array(next_record.layout.array)

assert buffers
assert np.shares_memory(
array.layout.content("x").content.data,
next_array.layout.content("x").content.data,
)
assert np.shares_memory(
array.layout.content("x").starts.data,
next_array.layout.content("x").starts.data,
)
assert np.shares_memory(
array.layout.content("x").stops.data,
next_array.layout.content("x").stops.data,
)

0 comments on commit 0af11a4

Please sign in to comment.