BUG: accessing df column with df.columns result type mismatch
See original GitHub issuePandas 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
df = pd.DataFrame([[1, 2, 3]], columns=["a", "b", "c"])
column = df.columns[0]
a = df[column]
print(a)
Issue Description
First sorry if this should be in Questions instead of bug. It may be my misunderstanding and it may be by design.
Pylance in VS Code attended Reproducible example complains about type as in this printscreen
This may be also problem of pylance of course.
Expected Behavior
I’d expect that used code is formally OK (it’s not usual way of iterating as iloc for example, but sometimes this may be the way).
It shows that result of df.columns[0]
is hashable. Yes it is, but maybe that it is particular type that implements same interface as hashable?
Installed Versions
INSTALLED VERSIONS
commit : 4bfe3d07b4858144c219b9346329027024102ab6 python : 3.10.4.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.22000 machine : AMD64 processor : AMD64 Family 23 Model 104 Stepping 1, AuthenticAMD byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : Czech_Czechia.1252
pandas : 1.4.2 numpy : 1.22.3 pytz : 2022.1 dateutil : 2.8.2 pip : 22.0.4 setuptools : 58.1.0 Cython : None pytest : 7.1.1 hypothesis : None sphinx : 4.5.0 blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.1.1 IPython : 8.2.0 pandas_datareader: None bs4 : None bottleneck : None brotli : None fastparquet : None fsspec : None gcsfs : None markupsafe : 2.1.1 matplotlib : 3.5.1 numba : None numexpr : 2.8.1 odfpy : None openpyxl : 3.0.9 pandas_gbq : None pyarrow : 7.0.0 pyreadstat : None pyxlsb : None s3fs : None scipy : 1.8.0 snappy : None sqlalchemy : 1.4.36 tables : 3.7.0 tabulate : 0.8.9 xarray : None xlrd : 2.0.1 xlwt : None zstandard : None
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
This is now fixed in the
pandas-stubs
repo via https://github.com/pandas-dev/pandas-stubs/pull/15Just a small spam here - As I turned on static type checker and refactored old code with pandas - I’ve found some edge cases and potential errors, so I love this feature…