Skip to content

Commit

Permalink
BUG: wrap __idiv__ to avoid making a copy (pandas-dev#12962)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkamm committed Sep 19, 2017
1 parent 6630c4e commit b334344
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/core/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def f(self, other):
__itruediv__=_wrap_inplace_method(new_methods["__truediv__"]),
__ipow__=_wrap_inplace_method(new_methods["__pow__"]), ))
if not compat.PY3:
new_methods["__idiv__"] = new_methods["__div__"]
new_methods["__idiv__"] = _wrap_inplace_method(new_methods["__div__"])

add_methods(cls, new_methods=new_methods, force=force, select=select,
exclude=exclude)
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/frame/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,21 @@ def test_inplace_ops_identity(self):
assert_frame_equal(df2, expected)
assert df._data is df2._data

# no id change
arr = np.array([1., 2., 3.])
df = DataFrame({'a': arr.copy()})
expected = id(df)
df += 2.
assert id(df) == expected
df -= 2.
assert id(df) == expected
df *= 2.
assert id(df) == expected
df /= 2.
assert id(df) == expected
df **= 2.
assert id(df) == expected

def test_alignment_non_pandas(self):
index = ['A', 'B', 'C']
columns = ['X', 'Y', 'Z']
Expand Down

0 comments on commit b334344

Please sign in to comment.