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

Deprecation warning in Jupyter notebook for use of ~ with Pandas series. #6810

Open
billtubbs opened this issue Jan 2, 2025 · 3 comments
Open
Assignees
Labels
waiting for user response Requires more information from user

Comments

@billtubbs
Copy link

billtubbs commented Jan 2, 2025

Environment data

  • Pylance version: 2024.12.1
  • OS and version: Ubuntu 22.04.3 in Docker, VSCode running on Windows 11
  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.12

Code Snippet

I am writing the following in a Jupyter notebook cell in VSCode:

np.sum(~data)

where data is a Pandas Series.

Repro Steps

This is quite hard to reproduce in any other notebook except here in the notebook where the screenshot below was taken. Other Pandas series in this notebook do not seem to have the same problem.

Expected behavior

I do not expect a deprecation warning since data is a Pandas series. As far as I know the use of the boolean negation operator is only being deprecated for Python bool types.

Actual behavior

This is formatted as shown in the following screenshot with a deprecation warning:

Image

The warning says

The method "invert" in class "bool" is deprecated
Will throw an error in Python 3.14. Use not for logical negation of bools instead.

Strangely, if I add any command assigning to data prior to this cell, the strike-through formatting and deprecation warning goes away:

Image

Hypothesis

It thinks data is a Python bool.

@rchiodo
Copy link
Contributor

rchiodo commented Jan 6, 2025

Thanks for the issue. We'd need the full notebook to reproduce. It sounds like the type of data is a bool but you're not expecting that.

@rchiodo rchiodo self-assigned this Jan 6, 2025
@rchiodo rchiodo added the waiting for user response Requires more information from user label Jan 6, 2025
@billtubbs
Copy link
Author

billtubbs commented Jan 6, 2025

Thanks, unfortunately it would be difficult to share the full notebook. I'll see if I can reproduce it in a notebook I could disclose.

The type of data is a Pandas series. See the output of print(type(data)) below the cell.

@github-actions github-actions bot added user responded Was "waiting for user response" and they responded and removed waiting for user response Requires more information from user labels Jan 6, 2025
@rchiodo
Copy link
Contributor

rchiodo commented Jan 6, 2025

The runtime might end up with a different type than static analysis does. Usually that's because some function that produces data isn't typed, so Pylance can't determine the type correctly.

@rchiodo rchiodo added waiting for user response Requires more information from user and removed user responded Was "waiting for user response" and they responded labels Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for user response Requires more information from user
Projects
None yet
Development

No branches or pull requests

2 participants