pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

Pandas imports

Open ZPyrolink opened this issue 8 months ago • 0 comments

Describe the Bug

Description

Depending on the import path used, pyrefly infers different type hints for the same objects in pandas.

For example:

import pandas as pd

df = pd.DataFrame([1,2,3]) # pyrefly detect Unknown
columns = df.columns # pyrefly detect Unknown

or

import pandas.core.api as pd

df = pd.DataFrame([1,2,3]) # pyrefly correctly detect DataFrame
columns = df.columns # but pyrefly detect Unknown

To have the correct typing:

import pandas.core.frame as pd

df = pd.DataFrame([1,2,3]) # pyrefly correctly detect DataFrame
columns = df.columns # pyrefly correctly detect Index

Commentary

I understand that internally we have imports of imports:

# On pandas
from pandas.core.api import DataFrame

# On pandas.core.api
from pandas.core.frame import DataFrame

# On pandas.core.frame
class DataFrame(...): ...`

The issue might come from here

Environment

  • pandas 2.2.3
  • pandas-stubs 2.2.3.250308

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

ZPyrolink avatar May 26 '25 14:05 ZPyrolink