File tree 2 files changed +6
-9
lines changed
2 files changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -517,6 +517,7 @@ def _transform_general(
517
517
"""
518
518
Transform with a non-str `func`.
519
519
"""
520
+ print ("Calling SeriesGroupBy._transform_general" )
520
521
if maybe_use_numba (engine ):
521
522
numba_func , cache_key = generate_numba_func (
522
523
func , engine_kwargs , kwargs , "groupby_transform"
@@ -1455,17 +1456,11 @@ def _transform_general(
1455
1456
applied .append (r )
1456
1457
else :
1457
1458
applied .append (res )
1458
-
1459
1459
concat_index = obj .columns if self .axis == 0 else obj .index
1460
1460
other_axis = 1 if self .axis == 0 else 0 # switches between 0 & 1
1461
1461
concatenated = concat (applied , axis = self .axis , verify_integrity = False )
1462
1462
concatenated = concatenated .reindex (concat_index , axis = other_axis , copy = False )
1463
- if not self .dropna or not has_nan :
1464
- return self ._set_result_index_ordered (concatenated )
1465
- else :
1466
- concatenated .sort_index (inplace = True )
1467
- concatenated .index = obj .index [concatenated .index .asi8 ]
1468
- return concatenated
1463
+ return self ._set_result_index_ordered (concatenated )
1469
1464
1470
1465
@Substitution (klass = "DataFrame" )
1471
1466
@Appender (_transform_template )
Original file line number Diff line number Diff line change @@ -682,15 +682,17 @@ def _set_group_selection(self):
682
682
def _set_result_index_ordered (self , result ):
683
683
# set the result index on the passed values object and
684
684
# return the new object, xref 8046
685
-
686
685
# the values/counts are repeated according to the group index
687
686
# shortcut if we have an already ordered grouper
688
687
if not self .grouper .is_monotonic :
689
688
index = Index (np .concatenate (self ._get_indices (self .grouper .result_index )))
690
689
result .set_axis (index , axis = self .axis , inplace = True )
691
690
result = result .sort_index (axis = self .axis )
692
691
693
- result .set_axis (self .obj ._get_axis (self .axis ), axis = self .axis , inplace = True )
692
+ result_idx , obj_idx = result .index , self .obj ._get_axis (self .axis )
693
+ intersection = result_idx .intersection (obj_idx )
694
+ indexer = obj_idx if intersection .empty else intersection
695
+ result .set_axis (indexer , axis = self .axis , inplace = True )
694
696
return result
695
697
696
698
def _dir_additions (self ):
You can’t perform that action at this time.
0 commit comments