Skip to content
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: df.A raises AttributeError if column index is of dtype string #46185

Closed
2 of 3 tasks
RagBlufThim opened this issue Feb 28, 2022 · 0 comments · Fixed by #46301
Closed
2 of 3 tasks

BUG: df.A raises AttributeError if column index is of dtype string #46185

RagBlufThim opened this issue Feb 28, 2022 · 0 comments · Fixed by #46301
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@RagBlufThim
Copy link

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

import pandas as pd
df1 = pd.DataFrame({0:list("Abc"), 1:list("Xyz")}, dtype="string")
df2 = df1.set_axis(df1.iloc[0], axis="columns")
df2.A  # raises AttributeError

Issue Description

df2.A raises AttributeError: 'DataFrame' object has no attribute 'A' even though df2 has a column A.
df2['A'] works as expected.
When I leave out the dtype="string" of the creation of df1, it works.
When I change the first argument of the .set_axis above to df1.iloc[0].astype('object') it works.
So df2.A works if the column index is of dtype object, but not if it is of dtype string.

Expected Behavior

df2.A works regardless of the dtype of the column index.
The Reproducable Example works with Pandas 1.2.4, probably because there every index is of dtype object.
(I noticed the bug after upgrading from 1.2.4 to 1.4.1, when production scripts stopped working.)

Installed Versions

INSTALLED VERSIONS

commit : 06d2301
python : 3.10.2.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19042
machine : AMD64
...

pandas : 1.4.1
numpy : 1.22.2
pytz : 2021.3
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.1.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None

@RagBlufThim RagBlufThim added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant