@@ -322,6 +322,7 @@ def _pandas_rename_axis(obj, axis, level, newname):
322
322
323
323
def _pandas_broadcast_to (left , right ):
324
324
"""right is either a DataFrame/Series or an Index"""
325
+ orig_left = left
325
326
# columns are ignored (they could be completely different)
326
327
right_index = right if isinstance (right , pd .Index ) else right .index
327
328
left_names = oset (left .index .names )
@@ -346,11 +347,18 @@ def _pandas_broadcast_to(left, right):
346
347
assert left_names < right_names , \
347
348
"%s is not a subset of %s" % (left_names , right_names )
348
349
350
+ if isinstance (left , pd .Series ):
351
+ left = left .to_frame ('__left__' )
349
352
rightdf = _pandas_index_as_df (right_index )
350
353
# left join because we use the levels of right but the labels of left
351
354
merged = left .merge (rightdf , how = 'left' , right_on = list (common_names ),
352
355
left_index = True , sort = False )
353
- return merged .set_index (right_index .names )
356
+ #XXX: do it inplace?
357
+ broadcasted = merged .set_index (right_index .names )
358
+ if isinstance (orig_left , pd .Series ):
359
+ assert broadcasted .columns == ['__left__' ]
360
+ broadcasted = broadcasted ['__left__' ]
361
+ return broadcasted
354
362
355
363
356
364
# We need this function because
0 commit comments