Skip to content

Commit 4726d13

Browse files
committed
fixed binops when align changes left's object type (eg DF -> Series)
1 parent 8bb20b6 commit 4726d13

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

larray/core.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1434,24 +1434,25 @@ def _binop(opname):
14341434
# }
14351435
# fill_value = fill_values.get(opname)
14361436
def opmethod(self, other):
1437-
pandas_method = getattr(self.data.__class__, opname)
14381437
if isinstance(other, PandasLArray):
14391438
axis, level, (self_al, other_al) = _pandas_align(self.data,
14401439
other.data,
14411440
join='left')
1442-
res_data = pandas_method(self_al, other_al, axis=axis,
1443-
level=level)
1441+
method = getattr(self_al, opname)
1442+
res_data = method(other_al, axis=axis, level=level)
1443+
# XXX: sometimes align changes the type of object (DF ->
1444+
# Series), we might want to convert it back
14441445
return self._wrap_pandas(res_data)
14451446
elif isinstance(other, LArray):
14461447
raise NotImplementedError("mixed LArrays")
14471448
elif isinstance(other, np.ndarray):
14481449
# XXX: not sure how clever Pandas is. We should be able to
14491450
# handle extra/missing axes of length 1 (that is why I
14501451
# separated the ndarray and scalar cases)
1451-
res_data = pandas_method(self.data, other)
1452+
res_data = getattr(self.data, opname)(other)
14521453
return self._wrap_pandas(res_data)
14531454
elif np.isscalar(other):
1454-
res_data = pandas_method(self.data, other)
1455+
res_data = getattr(self.data, opname)(other)
14551456
return self._wrap_pandas(res_data)
14561457
else:
14571458
raise TypeError("unsupported operand type(s) for %s: '%s' "

0 commit comments

Comments
 (0)