Skip to content

BUG: Index values not read-only #16453

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
chris-b1 opened this issue May 23, 2017 · 1 comment
Closed

BUG: Index values not read-only #16453

chris-b1 opened this issue May 23, 2017 · 1 comment
Labels
Bug Error Reporting Incorrect or improved errors from pandas Index Related to the Index class or subclasses

Comments

@chris-b1
Copy link
Contributor

# 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

@chris-b1 chris-b1 added Bug Error Reporting Incorrect or improved errors from pandas labels May 23, 2017
@chris-b1 chris-b1 added this to the Next Major Release milestone May 23, 2017
@mroeschke mroeschke added the Index Related to the Index class or subclasses label Jun 12, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
@phofl
Copy link
Member

phofl commented Apr 17, 2023

closing in favour of #33001

@phofl phofl closed this as completed Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error Reporting Incorrect or improved errors from pandas Index Related to the Index class or subclasses
Projects
None yet
Development

No branches or pull requests

3 participants