-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: Possible bad api side effect of replacing FrozenList with tuple #57607
Comments
https://github.com/search?q=%22index.names+%3D%3D+%5BNone%5D%22&type=code fwiw checking for |
Maybe we could return a Since |
What do you mean exactly with this? |
Consider something like this
Currently such code fails, because the FrozenList is not mutable (and also with the tuple it fails). But if this would return a list instead, that would actually "work", in the sense of not raising an error anymore, but I suppose it would not actually update the names? |
Sorry I meant immutability.
It appears for In [5]: df = pd.DataFrame([1], index=pd.MultiIndex(codes=[[0]], levels=[["a"]], names=[0]))
In [6]: df
Out[6]:
0
0
a 1
In [9]: df.index.names[0] = "a"
In [10]: df.index
Out[10]:
MultiIndex([('a',)],
names=[0]) |
Yes, but so that has the behaviour that I mentioned above of appearing to work (because it no longer raises an error about being immutable), while not actually working. I personally think it is perfectly fine that this doesn't work (that's how it always has been, and there are other APIs to change the name), but IMO it would be a UX regression if it no longer fails loudly. |
Maybe we also just restore the FrozenList? Not a strong preference but I think the pattern the OP established is pretty reasonable. I would really never expect |
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
Issue Description
This might not be considered a bug, but I would expect there to be symmetry in
df.set_index
anddf.index.names
. Previously whenindex.names
was a FrozenList, this would work. However a tuple has different semantics than a list throughout pandas.Expected Behavior
I would expect
Index.names
to work forset_index
.Installed Versions
INSTALLED VERSIONS
commit : f01ae20
python : 3.11.7.final.0
python-bits : 64
OS : Linux
OS-release : 6.7.4-arch1-1
Version : #1 SMP PREEMPT_DYNAMIC Mon, 05 Feb 2024 22:07:49 +0000
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 3.0.0.dev0+431.gf01ae209da
numpy : 1.24.4
pytz : 2023.3
dateutil : 2.8.2
setuptools : 69.1.1
pip : 24.0
Cython : 3.0.8
pytest : 7.4.0
hypothesis : 6.98.11
sphinx : 6.2.1
blosc : None
feather : None
xlsxwriter : 3.1.0
lxml.etree : 4.9.2
html5lib : 1.1
pymysql : 1.0.3
psycopg2 : 2.9.6
jinja2 : 3.1.2
IPython : 8.22.1
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
bottleneck : 1.3.7
fastparquet : 2023.4.0
fsspec : 2023.5.0
gcsfs : 2023.5.0
matplotlib : 3.7.1
numba : 0.57.0
numexpr : 2.8.4
odfpy : None
openpyxl : 3.1.2
pyarrow : 16.0.0.dev175+g2d44818d0
pyreadstat : 1.2.1
python-calamine : None
pyxlsb : 1.0.10
s3fs : 2023.5.0
scipy : 1.10.1
sqlalchemy : 2.0.14
tables : 3.8.0
tabulate : 0.9.0
xarray : 2023.5.0
xlrd : 2.0.1
zstandard : 0.21.0
tzdata : 2023.3
qtpy : 2.4.0
pyqt5 : None
The text was updated successfully, but these errors were encountered: