diff --git a/src/awkward/_v2/_connect/pyarrow.py b/src/awkward/_v2/_connect/pyarrow.py index cad2b050f7..971c94d50a 100644 --- a/src/awkward/_v2/_connect/pyarrow.py +++ b/src/awkward/_v2/_connect/pyarrow.py @@ -313,6 +313,7 @@ def popbuffers(paarray, awkwardarrow_type, storage_type, buffers): paarray.indices, None, storage_type.index_type, buffers ) index = masked_index.content.data + if not isinstance(masked_index, ak._v2.contents.UnmaskedArray): mask = masked_index.mask_as_bool(valid_when=False) if mask.any(): diff --git a/src/awkward/_v2/contents/bitmaskedarray.py b/src/awkward/_v2/contents/bitmaskedarray.py index 7092bb2633..c61381d9c3 100644 --- a/src/awkward/_v2/contents/bitmaskedarray.py +++ b/src/awkward/_v2/contents/bitmaskedarray.py @@ -15,6 +15,7 @@ from awkward._v2.forms.form import _parameters_equal np = ak.nplike.NumpyMetadata.instance() +numpy = ak.nplike.Numpy.instance() class BitMaskedArray(Content): @@ -228,7 +229,7 @@ def mask_as_bool(self, valid_when=None, nplike=None): bytemask.to(nplike), self._mask.to(nplike), len(self._mask), - 0 if valid_when else 1, + 0 if valid_when == self._valid_when else 1, self._lsb_order, ) ) @@ -568,3 +569,16 @@ def packed(self): self._identifier, self._parameters, ) + + def _to_list(self, behavior): + out = self._to_list_custom(behavior) + if out is not None: + return out + + mask = self.mask_as_bool(valid_when=True, nplike=numpy)[: self._length] + content = self._content._to_list(behavior) + out = [None] * self._length + for i, isvalid in enumerate(mask): + if isvalid: + out[i] = content[i] + return out diff --git a/src/awkward/_v2/contents/bytemaskedarray.py b/src/awkward/_v2/contents/bytemaskedarray.py index 419483c0ae..a3e3849a9a 100644 --- a/src/awkward/_v2/contents/bytemaskedarray.py +++ b/src/awkward/_v2/contents/bytemaskedarray.py @@ -844,3 +844,16 @@ def packed(self): self._identifier, self._parameters, ) + + def _to_list(self, behavior): + out = self._to_list_custom(behavior) + if out is not None: + return out + + mask = self.mask_as_bool(valid_when=True, nplike=numpy) + content = self._content._to_list(behavior) + out = [None] * len(self._mask) + for i, isvalid in enumerate(mask): + if isvalid: + out[i] = content[i] + return out diff --git a/src/awkward/_v2/contents/content.py b/src/awkward/_v2/contents/content.py index 82251043d2..88286ae321 100644 --- a/src/awkward/_v2/contents/content.py +++ b/src/awkward/_v2/contents/content.py @@ -1179,3 +1179,18 @@ def recursively_apply( "function_name": function_name, }, ) + + def tolist(self, behavior=None): + return self.to_list(behavior) + + def to_list(self, behavior=None): + return self.packed()._to_list(behavior) + + def _to_list_custom(self, behavior): + cls = ak._v2._util.arrayclass(self, behavior) + if cls.__getitem__ is not ak._v2.highlevel.Array.__getitem__: + array = cls(self) + out = [None] * len(self) + for i in range(len(self)): + out[i] = array[i] + return out diff --git a/src/awkward/_v2/contents/emptyarray.py b/src/awkward/_v2/contents/emptyarray.py index 610f9d6f59..6048f81532 100644 --- a/src/awkward/_v2/contents/emptyarray.py +++ b/src/awkward/_v2/contents/emptyarray.py @@ -282,3 +282,6 @@ def continuation(): def packed(self): return self + + def _to_list(self, behavior): + return [] diff --git a/src/awkward/_v2/contents/indexedarray.py b/src/awkward/_v2/contents/indexedarray.py index 4ffe4530d1..41eaf10511 100644 --- a/src/awkward/_v2/contents/indexedarray.py +++ b/src/awkward/_v2/contents/indexedarray.py @@ -1040,3 +1040,15 @@ def continuation(): def packed(self): return self.project().packed() + + def _to_list(self, behavior): + out = self._to_list_custom(behavior) + if out is not None: + return out + + index = self._index.to(numpy) + content = self._content._to_list(behavior) + out = [None] * len(index) + for i, ind in enumerate(index): + out[i] = content[ind] + return out diff --git a/src/awkward/_v2/contents/indexedoptionarray.py b/src/awkward/_v2/contents/indexedoptionarray.py index 80dd7d94a6..8eb4821410 100644 --- a/src/awkward/_v2/contents/indexedoptionarray.py +++ b/src/awkward/_v2/contents/indexedoptionarray.py @@ -1537,3 +1537,16 @@ def packed(self): self._identifier, self._parameters, ) + + def _to_list(self, behavior): + out = self._to_list_custom(behavior) + if out is not None: + return out + + index = self._index.to(numpy) + content = self._content._to_list(behavior) + out = [None] * len(index) + for i, ind in enumerate(index): + if ind >= 0: + out[i] = content[ind] + return out diff --git a/src/awkward/_v2/contents/listarray.py b/src/awkward/_v2/contents/listarray.py index 7a525d4e89..22c9cd6dc5 100644 --- a/src/awkward/_v2/contents/listarray.py +++ b/src/awkward/_v2/contents/listarray.py @@ -1137,3 +1137,6 @@ def continuation(): def packed(self): return self.toListOffsetArray64(True).packed() + + def _to_list(self, behavior): + return ListOffsetArray._to_list(self, behavior) diff --git a/src/awkward/_v2/contents/listoffsetarray.py b/src/awkward/_v2/contents/listoffsetarray.py index 4c2dee0696..999a88427a 100644 --- a/src/awkward/_v2/contents/listoffsetarray.py +++ b/src/awkward/_v2/contents/listoffsetarray.py @@ -1817,3 +1817,33 @@ def packed(self): return ListOffsetArray( next._offsets, content, next._identifier, next._parameters ) + + def _to_list(self, behavior): + if self.parameter("__array__") == "bytestring": + content = ak._v2._util.tobytes(self._content.data) + starts, stops = self.starts, self.stops + out = [None] * len(starts) + for i in range(len(starts)): + out[i] = content[starts[i] : stops[i]] + return out + + elif self.parameter("__array__") == "string": + content = ak._v2._util.tobytes(self._content.data) + starts, stops = self.starts, self.stops + out = [None] * len(starts) + for i in range(len(starts)): + out[i] = content[starts[i] : stops[i]].decode(errors="surrogateescape") + return out + + else: + out = self._to_list_custom(behavior) + if out is not None: + return out + + content = self._content._to_list(behavior) + starts, stops = self.starts, self.stops + out = [None] * len(starts) + + for i in range(len(starts)): + out[i] = content[starts[i] : stops[i]] + return out diff --git a/src/awkward/_v2/contents/numpyarray.py b/src/awkward/_v2/contents/numpyarray.py index a5afe8ed9f..bdfb5f8d8a 100644 --- a/src/awkward/_v2/contents/numpyarray.py +++ b/src/awkward/_v2/contents/numpyarray.py @@ -1071,3 +1071,17 @@ def continuation(): def packed(self): return self.contiguous().toRegularArray() + + def _to_list(self, behavior): + if self.parameter("__array__") == "byte": + return ak._v2._util.tobytes(self._data) + + elif self.parameter("__array__") == "char": + return ak._v2._util.tobytes(self._data).decode(errors="surrogateescape") + + else: + out = self._to_list_custom(behavior) + if out is not None: + return out + + return self._data.tolist() diff --git a/src/awkward/_v2/contents/recordarray.py b/src/awkward/_v2/contents/recordarray.py index d45ee2fb2d..bc4daf9cfb 100644 --- a/src/awkward/_v2/contents/recordarray.py +++ b/src/awkward/_v2/contents/recordarray.py @@ -777,3 +777,33 @@ def packed(self): self._identifier, self._parameters, ) + + def _to_list(self, behavior): + out = self._to_list_custom(behavior) + if out is not None: + return out + + cls = ak._v2._util.recordclass(self, behavior) + if cls is not ak._v2.highlevel.Record: + length = self._length + out = [None] * length + for i in range(length): + out[i] = cls(self[i]) + return out + + if self.is_tuple: + contents = [x._to_list(behavior) for x in self._contents] + length = self._length + out = [None] * length + for i in range(length): + out[i] = tuple(x[i] for x in contents) + return out + + else: + fields = self._fields + contents = [x._to_list(behavior) for x in self._contents] + length = self._length + out = [None] * length + for i in range(length): + out[i] = dict(zip(fields, [x[i] for x in contents])) + return out diff --git a/src/awkward/_v2/contents/regulararray.py b/src/awkward/_v2/contents/regulararray.py index da194098a2..9c70a49a02 100644 --- a/src/awkward/_v2/contents/regulararray.py +++ b/src/awkward/_v2/contents/regulararray.py @@ -1013,3 +1013,34 @@ def packed(self): return RegularArray( content, self._size, self._length, self._identifier, self._parameters ) + + def _to_list(self, behavior): + if self.parameter("__array__") == "bytestring": + content = ak._v2._util.tobytes(self._content.data) + length, size = self._length, self._size + out = [None] * length + for i in range(length): + out[i] = content[(i) * size : (i + 1) * size] + return out + + elif self.parameter("__array__") == "string": + content = ak._v2._util.tobytes(self._content.data) + length, size = self._length, self._size + out = [None] * length + for i in range(length): + out[i] = content[(i) * size : (i + 1) * size].decode( + errors="surrogateescape" + ) + return out + + else: + out = self._to_list_custom(behavior) + if out is not None: + return out + + content = self._content._to_list(behavior) + length, size = self._length, self._size + out = [None] * length + for i in range(length): + out[i] = content[(i) * size : (i + 1) * size] + return out diff --git a/src/awkward/_v2/contents/unionarray.py b/src/awkward/_v2/contents/unionarray.py index f7d729a4dd..be4e217059 100644 --- a/src/awkward/_v2/contents/unionarray.py +++ b/src/awkward/_v2/contents/unionarray.py @@ -217,7 +217,7 @@ def _carry(self, carry, allow_lazy, exception): def project(self, index): nplike = self.nplike lentags = len(self._tags) - assert len(self._index) == lentags + assert len(self._index) >= lentags lenout = ak._v2.index.Index64.empty(1, nplike) tmpcarry = ak._v2.index.Index64.empty(lentags, nplike) self._handle_error( @@ -958,17 +958,18 @@ def packed(self): nplike = self._tags.nplike tags = self._tags.to(nplike) - original_index = index = self._index.to(nplike) + original_index = index = self._index.to(nplike)[: len(tags)] contents = list(self._contents) for tag in range(len(self._contents)): is_tag = tags == tag num_tag = nplike.count_nonzero(is_tag) + if len(contents[tag]) > num_tag: if original_index is index: index = index.copy() - index[is_tag] = nplike.arange(num_tag) + index[is_tag] = nplike.arange(num_tag, dtype=index.dtype) contents[tag] = self.project(tag) contents[tag] = contents[tag].packed() @@ -980,3 +981,17 @@ def packed(self): self._identifier, self._parameters, ) + + def _to_list(self, behavior): + out = self._to_list_custom(behavior) + if out is not None: + return out + + tags = self._tags.to(numpy) + index = self._index.to(numpy) + contents = [x._to_list(behavior) for x in self._contents] + + out = [None] * len(tags) + for i, tag in enumerate(tags): + out[i] = contents[tag][index[i]] + return out diff --git a/src/awkward/_v2/contents/unmaskedarray.py b/src/awkward/_v2/contents/unmaskedarray.py index 8ec4873883..c458b8e92d 100644 --- a/src/awkward/_v2/contents/unmaskedarray.py +++ b/src/awkward/_v2/contents/unmaskedarray.py @@ -457,3 +457,10 @@ def continuation(): def packed(self): return UnmaskedArray(self._content.packed(), self._identifier, self._parameters) + + def _to_list(self, behavior): + out = self._to_list_custom(behavior) + if out is not None: + return out + + return self._content._to_list(behavior) diff --git a/src/awkward/_v2/highlevel.py b/src/awkward/_v2/highlevel.py index 87f24c90bc..ee42bc9b0e 100644 --- a/src/awkward/_v2/highlevel.py +++ b/src/awkward/_v2/highlevel.py @@ -9,8 +9,6 @@ # - [ ] `__array_ufunc__` # - [ ] `__array_function__` # - [ ] `numba_type` -# - [ ] `__getstate__` -# - [ ] `__setstate__` # - [ ] `__copy__` # - [ ] `__deepcopy__` # - [ ] `__contains__` @@ -21,8 +19,6 @@ # - [ ] 'nbytes' and maybe 'nbytes_held' # - [ ] `__array_ufunc__` # - [ ] `numba_type` -# - [ ] `__getstate__` -# - [ ] `__setstate__` # - [ ] `__copy__` # - [ ] `__deepcopy__` # - [ ] `__contains__` @@ -445,13 +441,13 @@ def tolist(self): (but without the underscore, like NumPy's [tolist](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.tolist.html)). """ - return ak._v2.operations.convert.to_list(self) + return self.to_list() def to_list(self): """ Converts this Array into Python objects; same as #ak.to_list. """ - return ak._v2.operations.convert.to_list(self) + return self._layout.to_list(self._behavior) def to_numpy(self, allow_missing=True): """ @@ -1318,7 +1314,7 @@ def show(self, limit_rows=20, limit_cols=80, type=False, stream=sys.stdout): # nested lists in a NumPy `"O"` array are severed from the array and # cannot be sliced as dimensions. # """ - # return ak._v2._connect.numpy.convert_to_array(self.layout, args, kwargs) + # return ak._v2._connect.numpy.convert_to_array(self._layout, args, kwargs) # def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): # """ @@ -1422,37 +1418,56 @@ def show(self, limit_rows=20, limit_cols=80, type=False, stream=sys.stdout): # return numba.typeof(self._numbaview) - # def __getstate__(self): - # packed = ak._v2.operations.structure.packed(self.layout, highlevel=False) - # form, length, container = ak._v2.operations.convert.to_buffers(packed) - # if self._behavior is ak._v2.behavior: - # behavior = None - # else: - # behavior = self._behavior - # return form, length, container, behavior - - # def __setstate__(self, state): - # if isinstance(state[1], dict): - # form, container, num_partitions, behavior = state - # layout = ak._v2._util.adjust_old_pickle( - # form, container, num_partitions, behavior - # ) - # else: - # form, length, container, behavior = state - # layout = ak._v2.operations.convert.from_buffers( - # form, length, container, highlevel=False, behavior=behavior - # ) - # if self.__class__ is Array: - # self.__class__ = ak._v2._util.arrayclass(layout, behavior) - # self.layout = layout - # self.behavior = behavior - # self._caches = ak._v2._util.find_caches(self.layout) + def __getstate__(self): + packed = ak._v2.operations.structure.packed(self._layout, highlevel=False) + form, length, container = ak._v2.operations.convert.to_buffers( + packed, buffer_key="part0-{form_key}-{attribute}", form_key="node{id}" + ) + if self._behavior is ak._v2.behavior: + behavior = None + else: + behavior = self._behavior + return form, length, container, behavior + + def __setstate__(self, state): + if isinstance(state[1], dict): + raise ValueError( + "Awkward 2.x and later can only unpickle arrays from 1.0.1 and later" + ) + else: + form, length, container, behavior = state + if ak._v2._util.isint(length): + layout = ak._v2.operations.convert.from_buffers( + form, + length, + container, + highlevel=False, + buffer_key="part0-{form_key}-{attribute}", + ) + else: + layouts = [ + ak._v2.operations.convert.from_buffers( + form, + length, + container, + highlevel=False, + buffer_key="part{0}-{{form_key}}-{{attribute}}".format(i), + ) + for i in length + ] + layout = ak._v2.operations.structure.concatenate( + layouts, highlevel=False + ) + if self.__class__ is Array: + self.__class__ = ak._v2._util.arrayclass(layout, behavior) + self.layout = layout + self.behavior = behavior # def __copy__(self): - # return Array(self.layout, behavior=self._behavior) + # return Array(self._layout, behavior=self._behavior) # def __deepcopy__(self, memo): - # return Array(self.layout.deep_copy(), behavior=self._behavior) + # return Array(self._layout.deep_copy(), behavior=self._behavior) def __bool__(self): if len(self) == 1: @@ -1465,7 +1480,7 @@ def __bool__(self): # def __contains__(self, element): -# for test in ak._v2._util.completely_flatten(self.layout): +# for test in ak._v2._util.completely_flatten(self._layout): # if element in test: # return True # return False @@ -1638,13 +1653,13 @@ def tolist(self): (but without the underscore, like NumPy's [tolist](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.tolist.html)). """ - return ak._v2.operations.convert.to_list(self) + return self.to_list() def to_list(self): """ Converts this Record into Python objects; same as #ak.to_list. """ - return ak._v2.operations.convert.to_list(self) + return self._layout.to_list(self._behavior) # @property # def nbytes(self): @@ -1664,7 +1679,7 @@ def to_list(self): # the (small) C++ nodes or Python objects that reference the (large) # array buffers. # """ - # return self.layout.nbytes + # return self._layout.nbytes @property def fields(self): @@ -1824,7 +1839,7 @@ def __dir__(self): + dir(super(Record, self)) + [ x - for x in self.layout.fields + for x in self._layout.fields if _dir_pattern.match(x) and not keyword.iskeyword(x) ] ) @@ -2009,38 +2024,57 @@ def show(self, limit_rows=20, limit_cols=80, type=False, stream=sys.stdout): # return numba.typeof(self._numbaview) - # def __getstate__(self): - # packed = ak._v2.operations.structure.packed(self._layout, highlevel=False) - # form, length, container = ak._v2.operations.convert.to_buffers(packed.array) - # if self._behavior is ak._v2.behavior: - # behavior = None - # else: - # behavior = self._behavior - # return form, length, container, behavior, packed.at - - # def __setstate__(self, state): - # if isinstance(state[1], dict): - # form, container, num_partitions, behavior, at = state - # layout = ak._v2._util.adjust_old_pickle( - # form, container, num_partitions, behavior - # ) - # else: - # form, length, container, behavior, at = state - # layout = ak._v2.operations.convert.from_buffers( - # form, length, container, highlevel=False, behavior=behavior - # ) - # layout = ak._v2.record.Record(layout, at) - # if self.__class__ is Record: - # self.__class__ = ak._v2._util.recordclass(layout, behavior) - # self.layout = layout - # self.behavior = behavior - # self._caches = ak._v2._util.find_caches(self.layout) + def __getstate__(self): + packed = ak._v2.operations.structure.packed(self._layout, highlevel=False) + form, length, container = ak._v2.operations.convert.to_buffers( + packed.array, buffer_key="part0-{form_key}-{attribute}", form_key="node{id}" + ) + if self._behavior is ak._v2.behavior: + behavior = None + else: + behavior = self._behavior + return form, length, container, behavior, packed.at + + def __setstate__(self, state): + if isinstance(state[1], dict): + raise ValueError( + "Awkward 2.x and later can only unpickle arrays from 1.0.1 and later" + ) + else: + form, length, container, behavior, at = state + if ak._v2._util.isint(length): + layout = ak._v2.operations.convert.from_buffers( + form, + length, + container, + highlevel=False, + buffer_key="part0-{form_key}-{attribute}", + ) + else: + layouts = [ + ak._v2.operations.convert.from_buffers( + form, + length, + container, + highlevel=False, + buffer_key="part{0}-{{form_key}}-{{attribute}}".format(i), + ) + for i in length + ] + layout = ak._v2.operations.structure.concatenate( + layouts, highlevel=False + ) + layout = ak._v2.record.Record(layout, at) + if self.__class__ is Record: + self.__class__ = ak._v2._util.recordclass(layout, behavior) + self.layout = layout + self.behavior = behavior # def __copy__(self): - # return Record(self.layout, behavior=self._behavior) + # return Record(self._layout, behavior=self._behavior) # def __deepcopy__(self, memo): - # return Record(self.layout.deep_copy(), behavior=self._behavior) + # return Record(self._layout.deep_copy(), behavior=self._behavior) def __bool__(self): raise ValueError( @@ -2050,7 +2084,7 @@ def __bool__(self): # def __contains__(self, element): -# for test in ak._v2._util.completely_flatten(self.layout): +# for test in ak._v2._util.completely_flatten(self._layout): # if element in test: # return True # return False diff --git a/src/awkward/_v2/operations/convert/ak_from_iter.py b/src/awkward/_v2/operations/convert/ak_from_iter.py index a284f14e54..16410dbef7 100644 --- a/src/awkward/_v2/operations/convert/ak_from_iter.py +++ b/src/awkward/_v2/operations/convert/ak_from_iter.py @@ -69,8 +69,10 @@ def from_iter( builder = ak.layout.ArrayBuilder(initial=initial, resize=resize) for x in iterable: builder.fromiter(x) + formstr, length, buffers = builder.to_buffers() form = ak._v2.forms.from_json(formstr) - out = ak._v2.operations.convert.from_buffers(form, length, buffers) - return ak._v2._util.wrap(out, behavior, highlevel) + return ak._v2.operations.convert.from_buffers( + form, length, buffers, highlevel=highlevel + ) diff --git a/src/awkward/_v2/record.py b/src/awkward/_v2/record.py index cc976fb5c9..e4be880678 100644 --- a/src/awkward/_v2/record.py +++ b/src/awkward/_v2/record.py @@ -165,3 +165,10 @@ def packed(self): return Record(self._array.packed(), self._at) else: return Record(self._array[self._at : self._at + 1].packed(), 0) + + def to_list(self, behavior=None): + cls = ak._v2._util.recordclass(self._array, behavior) + if cls is not ak._v2.highlevel.Record: + return cls(self) + + return self._array[self._at : self._at + 1].to_list(behavior)[0] diff --git a/src/awkward/operations/convert.py b/src/awkward/operations/convert.py index f5c11da67a..78f72e7b43 100644 --- a/src/awkward/operations/convert.py +++ b/src/awkward/operations/convert.py @@ -1002,28 +1002,16 @@ def to_list(array): elif isinstance(array, (ak.layout.Content, ak.partition.PartitionedArray)): return [to_list(x) for x in array] - elif isinstance(array, ak._v2.highlevel.Array): - return [to_list(x) for x in array] - - elif isinstance(array, ak._v2.highlevel.Record): - return to_list(array.layout) - - # elif isinstance(array, ak._v2.highlevel.ArrayBuilder): - # return to_list(array.snapshot()) - - elif isinstance(array, ak._v2.contents.Content): - import awkward._v2.tmp_for_testing - - return to_list(awkward._v2.tmp_for_testing.v2_to_v1(array)) - - elif isinstance(array, ak._v2.record.Record): - import awkward._v2.tmp_for_testing - - return to_list( - awkward._v2.tmp_for_testing.v2_to_v1(array.array[array.at : array.at + 1])[ - 0 - ] - ) + elif isinstance( + array, + ( + ak._v2.highlevel.Array, + ak._v2.highlevel.Record, + ak._v2.contents.Content, + ak._v2.record.Record, + ), + ): + return array.to_list() elif isinstance(array, dict): return dict((n, to_list(x)) for n, x in array.items()) diff --git a/tests/v2/test_0224-arrow-to-awkward.py b/tests/v2/test_0224-arrow-to-awkward.py index ad9816d554..eebcec13c2 100644 --- a/tests/v2/test_0224-arrow-to-awkward.py +++ b/tests/v2/test_0224-arrow-to-awkward.py @@ -9,6 +9,7 @@ from awkward._v2.tmp_for_testing import v1_to_v2 pyarrow = pytest.importorskip("pyarrow") +pytest.importorskip("awkward._v2._connect.pyarrow") pytestmark = pytest.mark.skipif( ak._util.py27, reason="No Python 2.7 support in Awkward 2.x" @@ -1114,6 +1115,7 @@ def test_arrow_dictarray_null(): pyarrow.array([0, 0, 2, None, 1, None, 2, 1, 1]), pyarrow.array(["one", "two", "three"]), ) + print(a) assert ak.to_list(ak._v2._connect.pyarrow.handle_arrow(a)) == [ "one", "one", diff --git a/tests/v2/test_0348-form-keys.py b/tests/v2/test_0348-form-keys.py index 98cc4b7e0b..ef005ff45d 100644 --- a/tests/v2/test_0348-form-keys.py +++ b/tests/v2/test_0348-form-keys.py @@ -19,14 +19,18 @@ # def test_numpyarray(): -# assert ak.from_buffers(*ak.to_buffers([1, 2, 3, 4, 5])).tolist() == [ +# assert ak.from_buffers( +# *ak.to_buffers(ak._v2.highlevel.Array([1, 2, 3, 4, 5])) +# ).tolist() == [ # 1, # 2, # 3, # 4, # 5, # ] -# assert pickle.loads(pickle.dumps(ak.Array([1, 2, 3, 4, 5]), -1)).tolist() == [ +# assert pickle.loads( +# pickle.dumps(ak._v2.highlevel.Array([1, 2, 3, 4, 5]), -1) +# ).tolist() == [ # 1, # 2, # 3, diff --git a/tests/v2/test_0404-array-validity-check.py b/tests/v2/test_0404-array-validity-check.py index e38e656ad3..040cb4f660 100644 --- a/tests/v2/test_0404-array-validity-check.py +++ b/tests/v2/test_0404-array-validity-check.py @@ -20,7 +20,7 @@ def test_BitMaskedArray(): mask, content, valid_when=False, length=13, lsb_order=False ) array = v1_to_v2(array) - assert np.asarray(array.mask_as_bool()).tolist() == [ + assert np.asarray(array.mask_as_bool(valid_when=True)).tolist() == [ True, True, False, diff --git a/tests/v2/test_0835-datetime-type-pyarrow.py b/tests/v2/test_0835-datetime-type-pyarrow.py index 05ee8a8f8b..e2f311ed45 100644 --- a/tests/v2/test_0835-datetime-type-pyarrow.py +++ b/tests/v2/test_0835-datetime-type-pyarrow.py @@ -36,8 +36,8 @@ def test_from_arrow(): ) ) assert ak.to_list(array) == [ - np.datetime64("2002-01-23T00:00:00.000"), - np.datetime64("2019-02-20T00:00:00.000"), + np.datetime64("2002-01-23"), + np.datetime64("2019-02-20"), ] array = awkward._v2._connect.pyarrow.handle_arrow( @@ -57,10 +57,7 @@ def test_from_arrow(): type=pyarrow.time64("ns"), ) ) - assert ak.to_list(array) == [ - np.datetime64("1970-01-01T01:00:00.000"), - np.datetime64("1970-01-01T02:30:00.000"), - ] + assert ak.to_list(array) == [3600000000000, 9000000000000] array = awkward._v2._connect.pyarrow.handle_arrow( pyarrow.array( @@ -123,10 +120,7 @@ def test_from_arrow(): type=pyarrow.timestamp("ns"), ) ) - assert ak.to_list(array) == [ - np.datetime64("2002-01-23T00:00:00.000"), - np.datetime64("2019-02-20T00:00:00.000"), - ] + assert ak.to_list(array) == [1011744000000000000, 1550620800000000000] array = awkward._v2._connect.pyarrow.handle_arrow( pyarrow.array( @@ -167,7 +161,4 @@ def test_from_arrow(): type=pyarrow.duration("ns"), ) ) - assert ak.to_list(array) == [ - np.timedelta64(5, "D"), - np.timedelta64(10, "D"), - ] + assert ak.to_list(array) == [432000000000000, 864000000000000]