Skip to content

BUG: Missing SettingwithCopyWarning with MultiIndex DataFrame #38270

Closed
@bersbersbers

Description

@bersbersbers
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions