facebook / facebook/pyrefly

Incorrect type resolution when indexing Pandas dataframe

Open
#2,117 6 comments 0 reactions 1 assignee Assigned to @shobhitmehro View on GitHub
configuration dataframe typechecking
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

Great work with the library!
I'm unsure whether this is problem in Pandas or in Pyrefly and unfortunately I don't understand this kind of complex typing things for me to check it but I'm sure you are better at it 😄

With the following code the `other_df` is resolved to be of type `Series[Any]` even though it should be a dataframe and then I get bad-assignment on the third line of the example.
```python
my_df = pd.DataFrame([[1, 2, 3], [4, 5, 6]], columns=pd.Index(["a", "b", "c"]))
other_df = my_df[["a", "b"]]
new_df: pd.DataFrame = other_df # pyrefly: ignore[bad-assignment]
```
It is also weird that when running `uv run pyrefly check --remove-unused-ignores` it removes the ignore-comment but gives the error anyways in VS Code.

This happens with VS Code extension v0.48.0 and uv installed version 0.48.0.

Pandas documentation about the expected behaviour can be found [here](https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#basics)

### Sandbox Link

_No response_

### (Only applicable for extension issues) IDE Information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.