@@ -970,6 +970,11 @@ def _cython_agg_blocks(self, how, alt=None, numeric_only=True, min_count=-1):
970
970
971
971
# call our grouper again with only this block
972
972
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
+
973
978
s = groupby (obj , self .grouper )
974
979
try :
975
980
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):
978
983
# continue and exclude the block
979
984
deleted_items .append (locs )
980
985
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
+
981
993
finally :
994
+ assert not isinstance (result , DataFrame )
995
+
982
996
if result is not no_result :
983
997
# see if we can cast the block back to the original dtype
984
998
result = maybe_downcast_numeric (result , block .dtype )
985
999
986
- if result . ndim == 1 and isinstance (result , np .ndarray ):
1000
+ if block . is_extension and isinstance (result , np .ndarray ):
987
1001
# 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
988
1005
try :
989
1006
# Cast back if feasible
990
1007
result = type (block .values )._from_sequence (
991
- result , dtype = block .values .dtype
1008
+ result . ravel () , dtype = block .values .dtype
992
1009
)
993
1010
except ValueError :
994
1011
# reshape to be valid for non-Extension Block
0 commit comments