BUG: using df.drop(labels=x, level='level_name') does not update df.index.levels #36227
Closed
1 of 3 tasks
Labels
Milestone
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
outputs:
FrozenList([['bar', 'baz', 'foo', 'qux'], ['one', 'two']])
despite dropping
one
from the second levelProblem description
When calling
df.drop(labels='one', level='second')
, one would expect that the dropped label would no longer appear indf.index.levels
since all rows with that label are dropped. However, the label persists in thedf.index.levels
despite not showing up indf.index.get_level_values('second')
. I would expect thatdf.index.levels
only include labels of entries currently indf
, not ones that were previously there but dropped.Expected Output
FrozenList([['bar', 'baz', 'foo', 'qux'], ['two']])
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : d9fff27
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 4.14.182-llgrid-10ms
Version : #1 SMP Fri May 29 11:57:47 EDT 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : C
LANG : C.UTF-8
LOCALE : None.None
pandas : 1.1.0
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.2
setuptools : 49.3.1.post20200810
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.17.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.0
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: