We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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.
Empty string multilevel column names that follow an indexed column are removed from results. import pandas as pd data = pd.DataFrame({('b', '', '', '', 'a', ''): []}) print(data.columns) print(data['b'].columns) results in this: MultiIndex([('b', '', '', '', 'a', '')], ) MultiIndex([('a', '')], )
Missing column levels after indexing. This seems to be explicitly programmed behavior, that recursively eats empty top column names, but I can't find anything about this in the user guide on indexing, nor why empty column names should be treated differently.
MultiIndex([('', '', '', 'a', '')], ) was expected for the second output.
MultiIndex([('', '', '', 'a', '')], )
This issue reproduces on:
Google colab:
pandas : 1.3.5 numpy : 1.21.6 pytz : 2022.6 dateutil : 2.8.2 pip : 21.1.3 setuptools : 57.4.0 Cython : 0.29.32 pytest : 3.6.4 hypothesis : None sphinx : 1.8.6 blosc : None feather : 0.4.1 xlsxwriter : None lxml.etree : 4.9.1 html5lib : 1.0.1 pymysql : None psycopg2 : 2.9.5 (dt dec pq3 ext lo64) jinja2 : 2.11.3 IPython : 7.9.0 pandas_datareader: 0.9.0 bs4 : 4.6.3 bottleneck : None fsspec : 2022.10.0 fastparquet : None gcsfs : None matplotlib : 3.2.2 numexpr : 2.8.4 odfpy : None openpyxl : 3.0.10 pandas_gbq : 0.17.9 pyarrow : 6.0.1 pyxlsb : None s3fs : None scipy : 1.7.3 sqlalchemy : 1.4.43 tables : 3.7.0 tabulate : 0.8.10 xarray : 0.20.2 xlrd : 1.1.0 xlwt : 1.3.0 numba : 0.56.4
Main-branch (2.0.0.dev0+697.g8020bf1b2)
pandas : 1.5.1 numpy : 1.23.0 pytz : 2022.1 dateutil : 2.8.2 setuptools : 59.6.0 pip : 22.0.2 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : 3.0.3 lxml.etree : 4.9.1 html5lib : None pymysql : None psycopg2 : 2.9.1 jinja2 : 3.1.2 IPython : 8.4.0 pandas_datareader: None bs4 : 4.11.1 bottleneck : 1.3.5 brotli : None fastparquet : None fsspec : None gcsfs : None matplotlib : 3.5.2 numba : None numexpr : None odfpy : None openpyxl : 3.0.10 pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : 1.8.1 snappy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : 2.0.1 xlwt : None zstandard : None tzdata : None
1.5.1:
The text was updated successfully, but these errors were encountered:
We have a couple of tests that are testing exactly this behavior. So don't think this should be considered a bug. (test_frame_mixed_depth_get)
This is from way back and has been around since forever (#2596) one of the tests was added there
Sorry, something went wrong.
We should maybe document this?
I think that's important, this behavior causes obscure KeyErrors when not considered.
KeyError
I'm also interested in the reasoning behind this explicitly implemented and tested behavior.
No branches or pull requests
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
Missing column levels after indexing. This seems to be explicitly programmed behavior, that recursively eats empty top column names, but I can't find anything about this in the user guide on indexing, nor why empty column names should be treated differently.
Expected Behavior
MultiIndex([('', '', '', 'a', '')], )
was expected for the second output.Installed Versions
This issue reproduces on:
Google colab:
pandas : 1.3.5
numpy : 1.21.6
pytz : 2022.6
dateutil : 2.8.2
pip : 21.1.3
setuptools : 57.4.0
Cython : 0.29.32
pytest : 3.6.4
hypothesis : None
sphinx : 1.8.6
blosc : None
feather : 0.4.1
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : 1.0.1
pymysql : None
psycopg2 : 2.9.5 (dt dec pq3 ext lo64)
jinja2 : 2.11.3
IPython : 7.9.0
pandas_datareader: 0.9.0
bs4 : 4.6.3
bottleneck : None
fsspec : 2022.10.0
fastparquet : None
gcsfs : None
matplotlib : 3.2.2
numexpr : 2.8.4
odfpy : None
openpyxl : 3.0.10
pandas_gbq : 0.17.9
pyarrow : 6.0.1
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : 1.4.43
tables : 3.7.0
tabulate : 0.8.10
xarray : 0.20.2
xlrd : 1.1.0
xlwt : 1.3.0
numba : 0.56.4
Main-branch (2.0.0.dev0+697.g8020bf1b2)
pandas : 1.5.1
numpy : 1.23.0
pytz : 2022.1
dateutil : 2.8.2
setuptools : 59.6.0
pip : 22.0.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.3
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : 2.9.1
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : 1.3.5
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
zstandard : None
tzdata : None
1.5.1:
pandas : 1.5.1
numpy : 1.23.0
pytz : 2022.1
dateutil : 2.8.2
setuptools : 59.6.0
pip : 22.0.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.3
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : 2.9.1
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : 1.3.5
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
zstandard : None
tzdata : None
The text was updated successfully, but these errors were encountered: