diff --git a/src/awkward/operations/ak_from_buffers.py b/src/awkward/operations/ak_from_buffers.py index eed547b60d..72e5ba48b6 100644 --- a/src/awkward/operations/ak_from_buffers.py +++ b/src/awkward/operations/ak_from_buffers.py @@ -136,6 +136,9 @@ def _impl( elif isinstance(form, dict): form = ak.forms.from_dict(form) + if isinstance(length, np.integer): + length = int(length) + if not (is_integer(length) and length >= 0): raise TypeError("'length' argument must be a non-negative integer") diff --git a/tests/test_2947_to_list_numpy_integer.py b/tests/test_2947_to_list_numpy_integer.py new file mode 100644 index 0000000000..e65eb18333 --- /dev/null +++ b/tests/test_2947_to_list_numpy_integer.py @@ -0,0 +1,18 @@ +# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE +from __future__ import annotations + +import numpy as np + +import awkward as ak + + +def test(): + """Check that to_list() does not break when the array is built from buffers + with a length of type np.int64. + """ + awk = ak.Array(np.ones((7, 0))) + form, length, container = ak.to_buffers(ak.to_packed(awk)) + awk_from_buf = ak.from_buffers(form, np.int64(length), container) + lst = awk_from_buf.to_list() + + assert len(lst) == length