Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: SettingWithCopyWarning should be raised on this Series assignement s.loc[label].iloc[ind] = val #46574

Closed
2 of 3 tasks
arnaudlegout opened this issue Mar 30, 2022 · 1 comment
Labels
Bug Copy / view semantics Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@arnaudlegout
Copy link
Contributor

Pandas version checks

  • I have checked that this issue has not already been reported.

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

In [21]: import pandas as pd

In [22]: pd.__version__
Out[22]: '1.4.1'

In [23]: s = pd.Series([1, 2, 3, 10], index=['a', 'b', 'c', 'a'])

In [24]: s
Out[24]:
a     1
b     2
c     3
a    10
dtype: int64

In [26]: s.loc['a'].iloc[-1] = 0

In [27]: s
Out[27]:
a     1
b     2
c     3
a    10
dtype: int64

Issue Description

On the line s.loc['a'].iloc[-1] = 0 there is no warning, and the assignment fails.

This issue has been reported in a comment of this other issue: #37333

As issue 37333 does not describe this problem, I decided to create a new more explicit issue on this problem.

Expected Behavior

On the line s.loc['a'].iloc[-1] = 0 a SettingWithCopyWarning must be raised.

Installed Versions

In [29]: pd.show_versions()

INSTALLED VERSIONS

commit : 06d2301
python : 3.10.0.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : fr_FR.cp1252

pandas : 1.4.1
numpy : 1.21.5
pytz : 2021.3
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.0.4
Cython : 0.29.25
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.8.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 8.1.1
pandas_datareader: 0.10.0
bs4 : None
bottleneck : 1.3.2
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.1
numba : 0.55.0
numexpr : 2.8.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 7.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : 1.4.27
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
zstandard : None

@arnaudlegout arnaudlegout added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 30, 2022
@phofl
Copy link
Member

phofl commented Apr 8, 2022

The other issue is basically the same, even if your case mentioned in the comment. Please post any further information there.

@phofl phofl closed this as completed Apr 8, 2022
@phofl phofl added Indexing Related to indexing on series/frames, not to indexes themselves Duplicate Report Duplicate issue or pull request Copy / view semantics and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Copy / view semantics Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

2 participants