Skip to content

Commit

Permalink
Bugfix: fix #973 (#974)
Browse files Browse the repository at this point in the history
* Test: add test for #973

* Bugfix: add `reshape(-1)` call for flattening NumPy array
  • Loading branch information
agoose77 authored Jul 1, 2021
1 parent 2de78ac commit 6982773
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/awkward/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,14 @@ def completely_flatten(array):

elif isinstance(array, ak.layout.NumpyArray):
if array.format.upper().startswith("M"):
return (ak.nplike.of(array).asarray(array.view_int64).view(array.format),)
return (
ak.nplike.of(array)
.asarray(array.view_int64)
.view(array.format)
.reshape(-1),
)
else:
return (ak.nplike.of(array).asarray(array),)
return (ak.nplike.of(array).asarray(array).reshape(-1),)

else:
raise RuntimeError(
Expand Down
13 changes: 13 additions & 0 deletions tests/test_0973-flatten-multidimensional-numpy-array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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


def test():
array = ak.from_numpy(np.zeros((3, 3, 5)))
flattened = ak.flatten(array, axis=None)
assert flattened.ndim == 1

0 comments on commit 6982773

Please sign in to comment.