Skip to content

BUG: Augmented arithmetic assignments will modify original series starting version 1.1.4 #38519

Closed
@nikita-ivanov

Description

@nikita-ivanov
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

import pandas as pd

s = pd.Series([1, 2, 3])
s1 = s.iloc[1:]
s1 -= 4
s

# output
# 0    1
# 1   -2
# 2   -1
# dtype: int64

s = pd.Series([1, 2, 3])
s1 = s.iloc[1:]
s1 = s1 - 4
s

# output
# 0    1
# 1    2
# 2    3
# dtype: int64

Problem description

Starting with version 1.1.4 when applying either of +=, -=, *= or /= operators on a series s1 that was sliced from original series s, the change propagates to original series s. When using normal assignment operators s1 = s1 - 4 the problem is not present, which leads to inconsistent behavior.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 67a3d42
python : 3.7.9.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 13, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 1.1.4
numpy : 1.17.2
pytz : 2020.4
dateutil : 2.8.0
pip : 20.3.3
setuptools : 51.0.0.post20201207
Cython : 0.28.5
pytest : 3.8.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.4
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions