@@ -332,6 +332,14 @@ def _class_to_name(cls: typing.Type[VectorProtocol]) -> str:
332
332
# the vector class ############################################################
333
333
334
334
335
+ def _yes_record (x : ak .Array ) -> typing .Optional [typing .Union [float , ak .Record ]]:
336
+ return x [0 ]
337
+
338
+
339
+ def _no_record (x : ak .Array ) -> typing .Optional [ak .Array ]:
340
+ return x
341
+
342
+
335
343
class VectorAwkward :
336
344
lib : types .ModuleType = numpy
337
345
@@ -362,7 +370,18 @@ def _wrap_result(
362
370
if returns == [float ] or returns == [bool ]:
363
371
return result
364
372
365
- elif (
373
+ if all (not isinstance (x , ak .Array ) for x in result ):
374
+ maybe_record = _yes_record
375
+ result = [
376
+ ak .Array (x .layout .array [x .layout .at : x .layout .at + 1 ])
377
+ if isinstance (x , ak .Record )
378
+ else ak .Array ([x ])
379
+ for x in result
380
+ ]
381
+ else :
382
+ maybe_record = _no_record
383
+
384
+ if (
366
385
len (returns ) == 1
367
386
and isinstance (returns [0 ], type )
368
387
and issubclass (returns [0 ], Azimuthal )
@@ -396,11 +415,13 @@ def _wrap_result(
396
415
else :
397
416
cls = cls .ProjectionClass2D
398
417
399
- return ak .zip (
400
- dict (zip (names , arrays )),
401
- depth_limit = first .layout .purelist_depth ,
402
- with_name = _class_to_name (cls ),
403
- behavior = None if vector ._awkward_registered else first .behavior ,
418
+ return maybe_record (
419
+ ak .zip (
420
+ dict (zip (names , arrays )),
421
+ depth_limit = first .layout .purelist_depth ,
422
+ with_name = _class_to_name (cls ),
423
+ behavior = None if vector ._awkward_registered else first .behavior ,
424
+ )
404
425
)
405
426
406
427
elif (
@@ -440,11 +461,13 @@ def _wrap_result(
440
461
names .append (name )
441
462
arrays .append (self [name ])
442
463
443
- return ak .zip (
444
- dict (zip (names , arrays )),
445
- depth_limit = first .layout .purelist_depth ,
446
- with_name = _class_to_name (cls .ProjectionClass2D ),
447
- behavior = None if vector ._awkward_registered else first .behavior ,
464
+ return maybe_record (
465
+ ak .zip (
466
+ dict (zip (names , arrays )),
467
+ depth_limit = first .layout .purelist_depth ,
468
+ with_name = _class_to_name (cls .ProjectionClass2D ),
469
+ behavior = None if vector ._awkward_registered else first .behavior ,
470
+ )
448
471
)
449
472
450
473
elif (
@@ -491,11 +514,13 @@ def _wrap_result(
491
514
else :
492
515
cls = cls .ProjectionClass3D
493
516
494
- return ak .zip (
495
- dict (zip (names , arrays )),
496
- depth_limit = first .layout .purelist_depth ,
497
- with_name = _class_to_name (cls ),
498
- behavior = None if vector ._awkward_registered else first .behavior ,
517
+ return maybe_record (
518
+ ak .zip (
519
+ dict (zip (names , arrays )),
520
+ depth_limit = first .layout .purelist_depth ,
521
+ with_name = _class_to_name (cls ),
522
+ behavior = None if vector ._awkward_registered else first .behavior ,
523
+ )
499
524
)
500
525
501
526
elif (
@@ -547,11 +572,13 @@ def _wrap_result(
547
572
names .append (name )
548
573
arrays .append (self [name ])
549
574
550
- return ak .zip (
551
- dict (zip (names , arrays )),
552
- depth_limit = first .layout .purelist_depth ,
553
- with_name = _class_to_name (cls .ProjectionClass3D ),
554
- behavior = None if vector ._awkward_registered else first .behavior ,
575
+ return maybe_record (
576
+ ak .zip (
577
+ dict (zip (names , arrays )),
578
+ depth_limit = first .layout .purelist_depth ,
579
+ with_name = _class_to_name (cls .ProjectionClass3D ),
580
+ behavior = None if vector ._awkward_registered else first .behavior ,
581
+ )
555
582
)
556
583
557
584
elif (
@@ -611,11 +638,13 @@ def _wrap_result(
611
638
names .append (name )
612
639
arrays .append (self [name ])
613
640
614
- return ak .zip (
615
- dict (zip (names , arrays )),
616
- depth_limit = first .layout .purelist_depth ,
617
- with_name = _class_to_name (cls .ProjectionClass4D ),
618
- behavior = None if vector ._awkward_registered else first .behavior ,
641
+ return maybe_record (
642
+ ak .zip (
643
+ dict (zip (names , arrays )),
644
+ depth_limit = first .layout .purelist_depth ,
645
+ with_name = _class_to_name (cls .ProjectionClass4D ),
646
+ behavior = None if vector ._awkward_registered else first .behavior ,
647
+ )
619
648
)
620
649
621
650
else :
0 commit comments