Skip to content

Commit b334344

Browse files
author
dkamm
committed
BUG: wrap __idiv__ to avoid making a copy (#12962)
1 parent 6630c4e commit b334344

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pandas/core/ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def f(self, other):
236236
__itruediv__=_wrap_inplace_method(new_methods["__truediv__"]),
237237
__ipow__=_wrap_inplace_method(new_methods["__pow__"]), ))
238238
if not compat.PY3:
239-
new_methods["__idiv__"] = new_methods["__div__"]
239+
new_methods["__idiv__"] = _wrap_inplace_method(new_methods["__div__"])
240240

241241
add_methods(cls, new_methods=new_methods, force=force, select=select,
242242
exclude=exclude)

pandas/tests/frame/test_operators.py

+15
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,21 @@ def test_inplace_ops_identity(self):
11611161
assert_frame_equal(df2, expected)
11621162
assert df._data is df2._data
11631163

1164+
# no id change
1165+
arr = np.array([1., 2., 3.])
1166+
df = DataFrame({'a': arr.copy()})
1167+
expected = id(df)
1168+
df += 2.
1169+
assert id(df) == expected
1170+
df -= 2.
1171+
assert id(df) == expected
1172+
df *= 2.
1173+
assert id(df) == expected
1174+
df /= 2.
1175+
assert id(df) == expected
1176+
df **= 2.
1177+
assert id(df) == expected
1178+
11641179
def test_alignment_non_pandas(self):
11651180
index = ['A', 'B', 'C']
11661181
columns = ['X', 'Y', 'Z']

0 commit comments

Comments
 (0)