@@ -471,8 +471,22 @@ def compute_dict_like(
471
471
472
472
keys += [key ] * len (key_data )
473
473
results += key_data
474
- else :
474
+ elif is_groupby :
475
475
# key used for column selection and output
476
+
477
+ df = obj .obj
478
+ results , keys = [], []
479
+ for key , how in func .items ():
480
+ for index in range (df .shape [1 ]):
481
+ col = df .iloc [:, index ]
482
+ if col .name != key :
483
+ continue
484
+
485
+ series = obj ._gotitem (key , ndim = 1 , subset = col )
486
+ result = getattr (series , op_name )(how , ** kwargs )
487
+ results .append (result )
488
+ keys .append (key )
489
+ else :
476
490
results = [
477
491
getattr (obj ._gotitem (key , ndim = 1 ), op_name )(how , ** kwargs )
478
492
for key , how in func .items ()
@@ -496,11 +510,14 @@ def wrap_results_dict_like(
496
510
is_ndframe = [isinstance (r , ABCNDFrame ) for r in result_data ]
497
511
498
512
if all (is_ndframe ):
499
- results = dict ( zip ( result_index , result_data ))
513
+ results = [ result for result in result_data if not result . empty ]
500
514
keys_to_use : Iterable [Hashable ]
501
- keys_to_use = [k for k in result_index if not results [ k ] .empty ]
515
+ keys_to_use = [k for k , v in zip ( result_index , result_data ) if not v .empty ]
502
516
# Have to check, if at least one DataFrame is not empty.
503
- keys_to_use = keys_to_use if keys_to_use != [] else result_index
517
+ if keys_to_use == []:
518
+ keys_to_use = result_index
519
+ results = result_data
520
+
504
521
if selected_obj .ndim == 2 :
505
522
# keys are columns, so we can preserve names
506
523
ktu = Index (keys_to_use )
@@ -509,7 +526,7 @@ def wrap_results_dict_like(
509
526
510
527
axis : AxisInt = 0 if isinstance (obj , ABCSeries ) else 1
511
528
result = concat (
512
- { k : results [ k ] for k in keys_to_use } ,
529
+ results ,
513
530
axis = axis ,
514
531
keys = keys_to_use ,
515
532
)
0 commit comments