File tree Expand file tree Collapse file tree 3 files changed +9
-12
lines changed Expand file tree Collapse file tree 3 files changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -386,6 +386,9 @@ def _wrap_applied_output(
386
386
)
387
387
assert values is not None
388
388
389
+ if len (data ) == 0 and len (values ) != 0 :
390
+ return values [0 ].to_frame ().T .iloc [:0 ]
391
+
389
392
if isinstance (values [0 ], dict ):
390
393
# GH #823 #24880
391
394
index = self .grouper .result_index
@@ -1005,6 +1008,9 @@ def _wrap_applied_output(
1005
1008
result = result .astype (data .dtypes , copy = False )
1006
1009
return result
1007
1010
1011
+ if len (data ) == 0 and len (values ) != 0 :
1012
+ return values [0 ].unstack ().to_frame ().T .iloc [:0 ]
1013
+
1008
1014
# GH12824
1009
1015
first_not_none = next (com .not_none (* values ), None )
1010
1016
Original file line number Diff line number Diff line change @@ -2491,24 +2491,15 @@ def ohlc(self) -> DataFrame:
2491
2491
@doc (DataFrame .describe )
2492
2492
def describe (self , ** kwargs ):
2493
2493
with self ._group_selection_context ():
2494
- if len (self ._selected_obj ) == 0 :
2495
- if self ._selected_obj .ndim == 1 :
2496
- return self ._selected_obj .describe (** kwargs ).to_frame ().T .iloc [:0 ]
2497
- else :
2498
- return (
2499
- self ._selected_obj .describe (** kwargs )
2500
- .unstack ()
2501
- .to_frame ()
2502
- .T .iloc [:0 ]
2503
- )
2504
-
2505
2494
result = self ._python_apply_general (
2506
2495
lambda x : x .describe (** kwargs ),
2507
2496
self ._selected_obj ,
2508
2497
not_indexed_same = True ,
2509
2498
)
2510
2499
if self .axis == 1 :
2511
2500
return result .T
2501
+ elif len (result ) == 0 :
2502
+ return result
2512
2503
return result .unstack ()
2513
2504
2514
2505
@final
Original file line number Diff line number Diff line change @@ -792,7 +792,7 @@ def apply(
792
792
# If group_keys is empty, then no function calls have been made,
793
793
# so we will not have raised even if this is an invalid dtype.
794
794
# So do one dummy call here to raise appropriate TypeError.
795
- f (data .iloc [:0 ])
795
+ result_values . append ( f (data .iloc [:0 ]) )
796
796
797
797
return result_values , mutated
798
798
You can’t perform that action at this time.
0 commit comments