You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rename does never find index values when using the level parameter to replace. When adding errors='raise', we get the following error:
Traceback (most recent call last):
File "/Users/bustawin/repos/venvs/bicing/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3441, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-15-54b8de4a3511>", line 1, in <module>
s.rename(index={'one': 'yes'}, level=1, errors='raise')
File "/Users/bustawin/repos/venvs/bicing/lib/python3.9/site-packages/pandas/core/series.py", line 4518, in rename
return super().rename(
File "/Users/bustawin/repos/venvs/bicing/lib/python3.9/site-packages/pandas/core/generic.py", line 1154, in rename
raise KeyError(f"{missing_labels} not found in axis")
KeyError: "['one'] not found in axis"
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 master branch of pandas.
Reproducible Example
Issue Description
rename
does never find index values when using thelevel
parameter to replace. When addingerrors='raise'
, we get the following error:The example dataframe is taken from the multi-index guide.
Expected Behavior
The above should have produced the following dataframe:
Installed Versions
INSTALLED VERSIONS
commit : 73c6825
python : 3.9.7.final.0
python-bits : 64
OS : Darwin
OS-release : 20.6.0
Version : Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.3.3
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 21.1.3
setuptools : 57.0.0
Cython : None
pytest : 6.2.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.3
html5lib : None
pymysql : None
psycopg2 : 2.9.1 (dt dec pq3 ext lo64)
jinja2 : 3.0.1
IPython : 7.27.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : 2021.08.1
fastparquet : None
gcsfs : None
matplotlib : 3.4.3
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : 5.0.0
pyxlsb : None
s3fs : None
scipy : 1.7.1
sqlalchemy : 1.3.24
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
numba : 0.53.1
The text was updated successfully, but these errors were encountered: