Please Improve Type Inference for DataFrame.loc[lambda df: ...]
#7768
lvlh2
started this conversation in
Enhancement
Replies: 1 comment
-
|
This is likely caused by the type stubs that Panda ships (which we bundle with Pylance). It would be the one to return the type information for the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Description:
In VS Code with the Pylance extension, type inference works correctly for lambda parameters in methods like
data.assign(rank=lambda df: df["n"].rank()), wheredfis properly recognized as aDataFrame. However, indata.loc[lambda df: df["n"].rank() > 5], the lambda parameterdfis inferred asUnknown, which breaks autocomplete and type hints.Works: df in assign() is correctly inferred as DataFrame
Fails: df in loc[] is inferred as Unknown
Why This Matters:
Using
lambdainside.loc[]is a common pandas pattern for conditional indexing. Proper type inference would:Please enhance Pylance's type inference to recognize the lambda parameter in
.loc[]as the same type as the calling DataFrame/Series.Beta Was this translation helpful? Give feedback.
All reactions