@@ -970,6 +970,11 @@ def _cython_agg_blocks(self, how, alt=None, numeric_only=True, min_count=-1):
970970
971971 # call our grouper again with only this block
972972 obj = self .obj [data .items [locs ]]
973+ if obj .shape [1 ] == 1 :
974+ # Avoid call to self.values that can occur in DataFrame
975+ # reductions; see GH#28949
976+ obj = obj .iloc [:, 0 ]
977+
973978 s = groupby (obj , self .grouper )
974979 try :
975980 result = s .aggregate (lambda x : alt (x , axis = self .axis ))
@@ -978,17 +983,29 @@ def _cython_agg_blocks(self, how, alt=None, numeric_only=True, min_count=-1):
978983 # continue and exclude the block
979984 deleted_items .append (locs )
980985 continue
986+
987+ # unwrap DataFrame to get array
988+ assert len (result ._data .blocks ) == 1
989+ result = result ._data .blocks [0 ].values
990+ if result .ndim == 1 and isinstance (result , np .ndarray ):
991+ result = result .reshape (1 , - 1 )
992+
981993 finally :
994+ assert not isinstance (result , DataFrame )
995+
982996 if result is not no_result :
983997 # see if we can cast the block back to the original dtype
984998 result = maybe_downcast_numeric (result , block .dtype )
985999
986- if result . ndim == 1 and isinstance (result , np .ndarray ):
1000+ if block . is_extension and isinstance (result , np .ndarray ):
9871001 # e.g. block.values was an IntegerArray
1002+ # (1, N) case can occur if block.values was Categorical
1003+ # and result is ndarray[object]
1004+ assert result .ndim == 1 or result .shape [0 ] == 1
9881005 try :
9891006 # Cast back if feasible
9901007 result = type (block .values )._from_sequence (
991- result , dtype = block .values .dtype
1008+ result . ravel () , dtype = block .values .dtype
9921009 )
9931010 except ValueError :
9941011 # reshape to be valid for non-Extension Block
0 commit comments