diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 74f760f382c76..d577cfbbd460d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -4806,13 +4806,14 @@ def _arith_op(left, right): return ops.dispatch_to_series(this, other, _arith_op) else: result = _arith_op(this.values, other.values) - - return self._constructor(result, index=new_index, columns=new_columns, - copy=False) + return self._constructor(result, + index=new_index, columns=new_columns, + copy=False) def _combine_match_index(self, other, func, level=None): left, right = self.align(other, join='outer', axis=0, level=level, copy=False) + assert left.index.equals(right.index) new_data = func(left.values.T, right.values).T return self._constructor(new_data, index=left.index, columns=self.columns, @@ -4821,6 +4822,7 @@ def _combine_match_index(self, other, func, level=None): def _combine_match_columns(self, other, func, level=None, try_cast=True): left, right = self.align(other, join='outer', axis=1, level=level, copy=False) + assert left.columns.equals(right.index) new_data = left._data.eval(func=func, other=right, axes=[left.columns, self.index], @@ -4829,12 +4831,7 @@ def _combine_match_columns(self, other, func, level=None, try_cast=True): def _combine_const(self, other, func, errors='raise', try_cast=True): if lib.is_scalar(other) or np.ndim(other) == 0: - new_data = {i: func(self.iloc[:, i], other) - for i, col in enumerate(self.columns)} - - result = self._constructor(new_data, index=self.index, copy=False) - result.columns = self.columns - return result + return ops.dispatch_to_series(self, other, func) new_data = self._data.eval(func=func, other=other, errors=errors, diff --git a/pandas/core/ops.py b/pandas/core/ops.py index b25809bf074f7..a86e57fd8876d 100644 --- a/pandas/core/ops.py +++ b/pandas/core/ops.py @@ -1638,6 +1638,7 @@ def dispatch_to_series(left, right, func): """ # Note: we use iloc to access columns for compat with cases # with non-unique columns. + right = lib.item_from_zerodim(right) if lib.is_scalar(right): new_data = {i: func(left.iloc[:, i], right) for i in range(len(left.columns))}