From e3bcfa1b92112e6d624cd1db10b10786eccba72a Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Wed, 1 Nov 2023 14:51:02 -0500 Subject: [PATCH 1/2] awkward main has Scalars returns as np.ndarray(N) --- src/dask_awkward/lib/core.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/dask_awkward/lib/core.py b/src/dask_awkward/lib/core.py index 26c5843a..17be6df5 100644 --- a/src/dask_awkward/lib/core.py +++ b/src/dask_awkward/lib/core.py @@ -539,11 +539,20 @@ def _finalize_array(results: Sequence[Any]) -> Any: if len(results) == 1: if isinstance(results[0], (int, ak.Array)): return results[0] + if isinstance(results[0], np.ndarray) and results[0].shape == (): + return results[0].item() # a sequence of arrays that need to be concatenated. elif any(isinstance(r, ak.Array) for r in results): return ak.concatenate(results) + # a sequence of scalars that are stored as np.ndarray(N) where N + # is a number (i.e. shapeless numpy array) + elif any(isinstance(r, np.ndarray) for r in results) and any( + r.shape == () for r in results + ): + return ak.Array(list(results)) + # sometimes we just check the length of partitions so all results # will be integers, just make an array out of that. elif isinstance(results, (tuple, list)) and all( From 5c4b41834de1d6c351299c0efbc4b1fc6923ceae Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Wed, 1 Nov 2023 15:03:26 -0500 Subject: [PATCH 2/2] collapse into a single case --- src/dask_awkward/lib/core.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/dask_awkward/lib/core.py b/src/dask_awkward/lib/core.py index 17be6df5..6f8924dc 100644 --- a/src/dask_awkward/lib/core.py +++ b/src/dask_awkward/lib/core.py @@ -537,10 +537,8 @@ def new_record_object(dsk: HighLevelGraph, name: str, *, meta: Any) -> Record: def _finalize_array(results: Sequence[Any]) -> Any: # special cases for length 1 results if len(results) == 1: - if isinstance(results[0], (int, ak.Array)): + if isinstance(results[0], (int, ak.Array, np.ndarray)): return results[0] - if isinstance(results[0], np.ndarray) and results[0].shape == (): - return results[0].item() # a sequence of arrays that need to be concatenated. elif any(isinstance(r, ak.Array) for r in results):