From c36d9d6688f5f8991ae71ae31c342cd0bf921726 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Tue, 9 Nov 2021 14:12:48 +0100 Subject: [PATCH] start --- src/awkward/_v2/contents/content.py | 3 +++ src/awkward/_v2/contents/numpyarray.py | 2 ++ tests/v2/test_0927-numpy-array-nbytes.py | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 tests/v2/test_0927-numpy-array-nbytes.py diff --git a/src/awkward/_v2/contents/content.py b/src/awkward/_v2/contents/content.py index 88286ae321..f86b408b48 100644 --- a/src/awkward/_v2/contents/content.py +++ b/src/awkward/_v2/contents/content.py @@ -1013,6 +1013,9 @@ def validityerror(self, path="layout"): return paramcheck return self._validityerror(path) + def nbytes(self): + return self._nbytes_part() + def purelist_parameter(self, key): return self.Form.purelist_parameter(self, key) diff --git a/src/awkward/_v2/contents/numpyarray.py b/src/awkward/_v2/contents/numpyarray.py index bdfb5f8d8a..a9e201efc2 100644 --- a/src/awkward/_v2/contents/numpyarray.py +++ b/src/awkward/_v2/contents/numpyarray.py @@ -985,6 +985,7 @@ def _validityerror(self, path): ) return "" + def _rpad(self, target, axis, depth, clip): if len(self.shape) == 0: raise ValueError("cannot rpad a scalar") @@ -1003,6 +1004,7 @@ def _rpad(self, target, axis, depth, clip): else: return self.rpad_axis0(target, clip=True) + def _to_arrow(self, pyarrow, mask_node, validbytes, length, options): if self._data.ndim != 1: return self.toRegularArray()._to_arrow( diff --git a/tests/v2/test_0927-numpy-array-nbytes.py b/tests/v2/test_0927-numpy-array-nbytes.py new file mode 100644 index 0000000000..59917943ef --- /dev/null +++ b/tests/v2/test_0927-numpy-array-nbytes.py @@ -0,0 +1,20 @@ +# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE + +from __future__ import absolute_import + +import pytest # noqa: F401 +import numpy as np # noqa: F401 +import awkward as ak # noqa: F401 + +from awkward._v2.tmp_for_testing import v1_to_v2, v1_to_v2_index + +pytestmark = pytest.mark.skipif( + ak._util.py27, reason="No Python 2.7 support in Awkward 2.x" +) + +def test(): + np_data = np.random.random(size=(4, 100 * 1024 * 1024 // 8 // 4)) + array = ak.from_numpy(np_data, regulararray=False) + array = v1_to_v2(array.layout) + + assert np_data.nbytes == array.nbytes()