Skip to content

BUG: Missing SettingwithCopyWarning with MultiIndex DataFrame #38270

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

Closed
2 tasks done
bersbersbers opened this issue Dec 3, 2020 · 1 comment · Fixed by #56614
Closed
2 tasks done

BUG: Missing SettingwithCopyWarning with MultiIndex DataFrame #38270

bersbersbers opened this issue Dec 3, 2020 · 1 comment · Fixed by #56614
Labels
Bug Copy / view semantics Warnings Warnings that appear or should be added to pandas

Comments

@bersbersbers
Copy link

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

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

Code Sample, a copy-pastable example

"""Missing SettingwithCopyWarning."""
import pandas as pd

df = pd.DataFrame(
    [["Alice", 10]],
    columns=pd.MultiIndex.from_product([["person"], ["first_name", "age"]]),
)
df.person.age = 11
print(df)

Problem description

Value 11 is not assigned. Output is

      person    
  first_name age
0      Alice  10

No SettingwithCopyWarning is shown.

Expected Output

Value 11 is assigned. Output is

      person    
  first_name age
0      Alice  11

Or: SettingwithCopyWarning is shown.

Output of pd.show_versions()


INSTALLED VERSIONS
------------------
commit           : 67a3d4241ab84419856b84fc3ebc9abcbe66c6b3
python           : 3.8.6.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.3.18-lp152.44-default
Version          : #1 SMP Wed Sep 30 18:51:43 UTC 2020 (914f31e)
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.1.4
numpy            : 1.19.4
pytz             : 2020.4
dateutil         : 2.8.1
pip              : 20.3.1
setuptools       : 50.3.2
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : 1.3.7
lxml.etree       : 4.6.2
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : None
IPython          : None
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             : 1.2.0
xlwt             : None
@bersbersbers bersbersbers added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 3, 2020
@bersbersbers
Copy link
Author

bersbersbers commented Dec 3, 2020

I know that this works:

"""Workaround."""
import pandas as pd

df = pd.DataFrame(
    [["Alice", 10]],
    columns=pd.MultiIndex.from_product([["person"], ["first_name", "age"]]),
)
df.loc[:, ("person", "age")] = 11
print(df)

But the point of this issue is that the non-working variante should issue a warning.

@arw2019 arw2019 added Copy / view semantics and removed Copy / view semantics Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 9, 2020
@mroeschke mroeschke added the Warnings Warnings that appear or should be added to pandas label Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Copy / view semantics Warnings Warnings that appear or should be added to pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants