# Your code here
df = pd.DataFrame({'a': [1,2,3]}, index=[4,5,6])

df.loc[4, :]
Out[93]: 
a    1
Name: 4, dtype: int64

df.index.values[0] = 10  # should raise

df
Out[95]: 
    a
10  1
5   2
6   3

df.loc[10, :]
KeyError: 'the label [10] is not in the [index]'

Problem description

Index.values should be read-only, otherwise the Index can get into an out-of-sync state like above where certain locations aren't find-able. Not a high priority as this is a pretty strange thing to do, but should be easy enough to set flags so this raises.

Expected Output

df.index._data.flags.writeable = False

df.index.values[0] = 1
ValueError: assignment destination is read-only

Output of pd.show_versions()

# Paste the output here pd.show_versions() here INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Windows OS-release: 7 machine: AMD64 processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None pandas: 0.20.1 pytest: 2.9.2 pip: 9.0.1 setuptools: 34.3.3 Cython: 0.24.1 numpy: 1.11.3 scipy: 0.19.0 xarray: 0.9.5 IPython: 5.1.0 sphinx: 1.3.1 patsy: 0.4.1 dateutil: 2.5.3 pytz: 2016.4 blosc: None bottleneck: 1.1.0 tables: 3.2.2 numexpr: 2.6.2 feather: None matplotlib: 2.0.0 openpyxl: 2.3.2 xlrd: 1.0.0 xlwt: 1.1.2 xlsxwriter: 0.9.2 lxml: 3.7.3 bs4: 4.5.3 html5lib: 0.999999999 sqlalchemy: 1.0.13 pymysql: None psycopg2: 2.7.1 (dt dec pq3 ext lo64) jinja2: 2.8 s3fs: None pandas_gbq: None pandas_datareader: 0.3.0.post

Comment From: phofl

closing in favour of #33001