question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: accessing df column with df.columns result type mismatch

See original GitHub issue

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

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

image

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:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Dr-Irvcommented, May 24, 2022

This is now fixed in the pandas-stubs repo via https://github.com/pandas-dev/pandas-stubs/pull/15

1reaction
Malachovcommented, May 20, 2022

Just 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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pandas join results in mismatch shape - Stack Overflow
this dataframe is very large and I am not sure about all the IDs in it. Frame B: OB_ID CA_ID colZ 1 1...
Read more >
How To Handle Data Type Mismatch In Pandas - Rasgo
This tutorial explains how to identify data in columns with the wrong data type with pandas. Packages. This tutorial uses: pandas · datetime....
Read more >
KeyError Pandas – How To Fix - Data Independent
Error catch option: Use df.get('your column') to look for your column value. ... your code and debug where your expectations and dataframe columns...
Read more >
Type mismatch error in scala | Edureka Community
You are trying to put an entire dataframe into a column, this is not allowed. If you want to get last version key...
Read more >
pandas.testing.assert_frame_equal - DataFrame
This function is intended to compare two DataFrames and output any differences. It is mostly intended for use in unit tests. Additional parameters...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found