Skip to content

Commit f238d32

Browse files
committed
added support for broadcasting Series in _pandas_broadcast_to
1 parent 94baeb3 commit f238d32

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

larray/utils.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ def _pandas_rename_axis(obj, axis, level, newname):
322322

323323
def _pandas_broadcast_to(left, right):
324324
"""right is either a DataFrame/Series or an Index"""
325+
orig_left = left
325326
# columns are ignored (they could be completely different)
326327
right_index = right if isinstance(right, pd.Index) else right.index
327328
left_names = oset(left.index.names)
@@ -346,11 +347,18 @@ def _pandas_broadcast_to(left, right):
346347
assert left_names < right_names, \
347348
"%s is not a subset of %s" % (left_names, right_names)
348349

350+
if isinstance(left, pd.Series):
351+
left = left.to_frame('__left__')
349352
rightdf = _pandas_index_as_df(right_index)
350353
# left join because we use the levels of right but the labels of left
351354
merged = left.merge(rightdf, how='left', right_on=list(common_names),
352355
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
354362

355363

356364
# We need this function because

0 commit comments

Comments
 (0)