@@ -412,8 +412,13 @@ def _python_apply_general(self, func, *args, **kwargs):
412
412
not_indexed_same = False
413
413
for key , group in self :
414
414
group .name = key
415
+
416
+ # group might be modified
417
+ group_axes = _get_axes (group )
418
+
415
419
res = func (group , * args , ** kwargs )
416
- if not _is_indexed_like (res , group ):
420
+
421
+ if not _is_indexed_like (res , group_axes ):
417
422
not_indexed_same = True
418
423
419
424
result_keys .append (key )
@@ -460,18 +465,19 @@ def groupby(obj, by, **kwds):
460
465
return klass (obj , by , ** kwds )
461
466
groupby .__doc__ = GroupBy .__doc__
462
467
463
- def _is_indexed_like (obj , other ):
468
+ def _get_axes (group ):
469
+ if isinstance (group , Series ):
470
+ return [group .index ]
471
+ else :
472
+ return group .axes
473
+
474
+ def _is_indexed_like (obj , axes ):
464
475
if isinstance (obj , Series ):
465
- if not isinstance ( other , Series ) :
476
+ if len ( axes ) > 1 :
466
477
return False
467
- return obj .index .equals (other . index )
478
+ return obj .index .equals (axes [ 0 ] )
468
479
elif isinstance (obj , DataFrame ):
469
- if isinstance (other , Series ):
470
- return obj .index .equals (other .index )
471
-
472
- # deal with this when a case arises
473
- assert (isinstance (other , DataFrame ))
474
- return obj ._indexed_same (other )
480
+ return obj .index .equals (axes [0 ])
475
481
476
482
return False
477
483
@@ -1093,11 +1099,7 @@ def _concat_frames(frames, index, columns=None, axis=0):
1093
1099
return result .reindex (index = index , columns = columns )
1094
1100
1095
1101
def _concat_indexes (indexes ):
1096
- if len (indexes ) == 1 :
1097
- new_index = indexes [0 ]
1098
- else :
1099
- new_index = indexes [0 ].append (indexes [1 :])
1100
- return new_index
1102
+ return indexes [0 ].append (indexes [1 :])
1101
1103
1102
1104
def _concat_frames_hierarchical (frames , keys , groupings , axis = 0 ):
1103
1105
if axis == 0 :
@@ -1135,8 +1137,14 @@ def _make_concat_multiindex(indexes, keys, groupings):
1135
1137
to_concat .append (np .repeat (k , len (index )))
1136
1138
label_list .append (np .concatenate (to_concat ))
1137
1139
1138
- # these go in the last level
1139
- label_list .append (np .concatenate (indexes ))
1140
+ concat_index = _concat_indexes (indexes )
1141
+
1142
+ # these go at the end
1143
+ if isinstance (concat_index , MultiIndex ):
1144
+ for level in range (concat_index .nlevels ):
1145
+ label_list .append (concat_index .get_level_values (level ))
1146
+ else :
1147
+ label_list .append (concat_index .values )
1140
1148
1141
1149
return MultiIndex .from_arrays (label_list )
1142
1150
0 commit comments