@@ -609,6 +609,23 @@ def _cython_operation(
609
609
kind , values , how , axis , min_count , ** kwargs
610
610
)
611
611
612
+ elif values .ndim == 1 :
613
+ # expand to 2d, dispatch, then squeeze if appropriate
614
+ values2d = values [None , :]
615
+ res = self ._cython_operation (
616
+ kind = kind ,
617
+ values = values2d ,
618
+ how = how ,
619
+ axis = 1 ,
620
+ min_count = min_count ,
621
+ ** kwargs ,
622
+ )
623
+ if res .shape [0 ] == 1 :
624
+ return res [0 ]
625
+
626
+ # otherwise we have OHLC
627
+ return res .T
628
+
612
629
is_datetimelike = needs_i8_conversion (dtype )
613
630
614
631
if is_datetimelike :
@@ -629,22 +646,20 @@ def _cython_operation(
629
646
values = values .astype (object )
630
647
631
648
arity = self ._cython_arity .get (how , 1 )
649
+ ngroups = self .ngroups
632
650
633
- vdim = values .ndim
634
- swapped = False
635
- if vdim == 1 :
636
- values = values [:, None ]
637
- out_shape = (self .ngroups , arity )
651
+ assert axis == 1
652
+ values = values .T
653
+ if how == "ohlc" :
654
+ out_shape = (ngroups , 4 )
655
+ elif arity > 1 :
656
+ raise NotImplementedError (
657
+ "arity of more than 1 is not supported for the 'how' argument"
658
+ )
659
+ elif kind == "transform" :
660
+ out_shape = values .shape
638
661
else :
639
- if axis > 0 :
640
- swapped = True
641
- assert axis == 1 , axis
642
- values = values .T
643
- if arity > 1 :
644
- raise NotImplementedError (
645
- "arity of more than 1 is not supported for the 'how' argument"
646
- )
647
- out_shape = (self .ngroups ,) + values .shape [1 :]
662
+ out_shape = (ngroups ,) + values .shape [1 :]
648
663
649
664
func , values = self ._get_cython_func_and_vals (kind , how , values , is_numeric )
650
665
@@ -658,13 +673,11 @@ def _cython_operation(
658
673
659
674
codes , _ , _ = self .group_info
660
675
676
+ result = maybe_fill (np .empty (out_shape , dtype = out_dtype ))
661
677
if kind == "aggregate" :
662
- result = maybe_fill (np .empty (out_shape , dtype = out_dtype ))
663
678
counts = np .zeros (self .ngroups , dtype = np .int64 )
664
679
result = self ._aggregate (result , counts , values , codes , func , min_count )
665
680
elif kind == "transform" :
666
- result = maybe_fill (np .empty (values .shape , dtype = out_dtype ))
667
-
668
681
# TODO: min_count
669
682
result = self ._transform (
670
683
result , values , codes , func , is_datetimelike , ** kwargs
@@ -680,11 +693,7 @@ def _cython_operation(
680
693
assert result .ndim != 2
681
694
result = result [counts > 0 ]
682
695
683
- if vdim == 1 and arity == 1 :
684
- result = result [:, 0 ]
685
-
686
- if swapped :
687
- result = result .swapaxes (0 , axis )
696
+ result = result .T
688
697
689
698
if how not in base .cython_cast_blocklist :
690
699
# e.g. if we are int64 and need to restore to datetime64/timedelta64
0 commit comments