def test_Record(): record = awkward1.Record({"x": 1, "y": [1, 2, 3]}) @numba.njit def f1(): return record.y[1] assert f1() == 2
def test_record(): assert awkward1.to_list(awkward1.Record({ "x": 1, "y": 2.2 })) == { "x": 1, "y": 2.2 }
def test(): np_array = numpy.array([0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]) one = awkward1.Array(np_array) np_array[1] = 999 assert awkward1.to_list(one) == [ 0.0, 999, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 ] two = copy.copy(one) np_array[3] = 123 assert awkward1.to_list(two) == [ 0.0, 999, 2.2, 123, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 ] three = copy.deepcopy(two) four = numpy.copy(two) np_array[5] = 321 assert awkward1.to_list(three) == [ 0.0, 999, 2.2, 123, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 ] assert awkward1.to_list(four) == [ 0.0, 999, 2.2, 123, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 ] assert awkward1.to_list( copy.deepcopy(awkward1.Array([[1, 2, 3], [], [4, 5]]))) == [[1, 2, 3], [], [4, 5]] assert awkward1.to_list( copy.deepcopy(awkward1.Record({ "one": 1, "two": 2.2 }))) == awkward1.to_list( copy.deepcopy(awkward1.Record({ "one": 1, "two": 2.2 })))
def _apply_global_index(self, index): """Internal method to take from a collection using a flat index This is often necessary to be able to still resolve cross-references on reduced arrays or single records. """ if isinstance(index, int): out = self._content()[index] return awkward1.Record(out, behavior=self.behavior) def flat_take(layout): idx = awkward1.Array(layout) return self._content()[idx.mask[idx >= 0]] def descend(layout, depth): if layout.purelist_depth == 1: return lambda: flat_take(layout) (index, ) = awkward1.broadcast_arrays(index) out = awkward1._util.recursively_apply(index.layout, descend) return awkward1.Array(out, behavior=self.behavior)
def test_record(): assert pickle.loads( pickle.dumps(awkward1.Record({ "x": 2.2, "y": [1, 2] }), -1)) == { "x": 2.2, "y": [1, 2] } assert pickle.loads( pickle.dumps( awkward1.Array([{ "x": 1.1, "y": [1] }, { "x": 2.2, "y": [1, 2] }, { "x": 3.3, "y": [1, 2, 3] }])[1], -1)) == { "x": 2.2, "y": [1, 2] }