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

False positive for operator in in pandas #202

Closed
ncarve opened this issue Aug 5, 2020 · 2 comments
Closed

False positive for operator in in pandas #202

ncarve opened this issue Aug 5, 2020 · 2 comments
Assignees
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@ncarve
Copy link

ncarve commented Aug 5, 2020

Environment data

  • Language Server version: 2020.7.4
  • OS and version: Ubuntu 18.04
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.7 (Anaconda)
  • Pandas version: 1.0.5

Expected behaviour

Pylance should not detect any error when using the in operator on pandas Index objects (for example 'c1' in df.columns)

Actual behaviour

Pylance raises the following error when the in operator is used on a pandas Index object:

Operator "in" not supported for types "str" and "Index[_str]"

The code itself executes just fine. This happens for example when in or not in is used on a DataFrame's columns or index properties.

Code Snippet / Additional information

import pandas as pd

df = pd.DataFrame(columns=['c1', 'c2'], data=[[1, 2], [3, 4]], index=['i1', 'i2'])

if 'c1' in df.columns:
    print('ok')
if 'i1' in df.index:
    print('ok')
@github-actions github-actions bot added the triage label Aug 5, 2020
@erictraut
Copy link
Contributor

@gramster, this is a bug in the type stub. It's missing the __contains__ magic method in the Index class.

@judej judej added the bug Something isn't working label Aug 5, 2020
@github-actions github-actions bot removed the triage label Aug 5, 2020
@jakebailey jakebailey added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Aug 10, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2020.8.1, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202081-13-august-2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

5 participants