Pandas version checks

  • [x] I have checked that this issue has not already been reported.

  • [x] I have confirmed this bug exists on the latest version of pandas.

  • [ ] I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

Create a pandas.api.extensions.register_dataframe_accessor, then when using try to command + click in VSCode to jump to the definition. Either no definition is found or it jumps to a file like series.pyi

Create a pandas.api.extensions.register_dataframe_accessor, then when using try to command + click in VSCode to jump to the definition. Either no definition is found or it jumps to a file like series.pyi

my_utils/my_accessor.py

import pandas as pd

@pd.api.extensions.register_dataframe_accessor("demo")
class DemoAccessor:
    def __init__(self, pandas_obj):
        self._obj = pandas_obj

    def say_hello(self):
        print("Hello from accessor!")

main.py

import pandas as pd
import sys
import importlib

# Ensure the path to the module is in sys.path
sys.path.append("my_utils")  # Adjust this path as needed

import my_accessor
importlib.reload(my_accessor)

# Create DataFrame and use accessor
df = pd.DataFrame({"A": [1, 2, 3]})
df.demo.say_hello()  # This runs fine, but "jump to definition" doesn't work

Issue Description

VSCode go to definition doesn't work with pandas.api.extensions.register_dataframe_accessor

Expected Behavior

I can jump to the definition when command clicking and see the documentation in VSCode

Installed Versions

INSTALLED VERSIONS ------------------ commit : d9cdd2ee5a58015ef6f4d15c7226110c9aab8140 python : 3.11.6.final.0 python-bits : 64 OS : Darwin OS-release : 24.3.0 Version : Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 2.2.2 numpy : 2.0.2 pytz : 2025.2 dateutil : 2.9.0.post0 setuptools : 80.7.1 pip : 25.1.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.1.6 IPython : 7.34.0 pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : 4.13.4 bottleneck : None dataframe-api-compat : None fastparquet : None fsspec : None gcsfs : None matplotlib : 3.10.0 numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : 1.15.3 sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None zstandard : None tzdata : 2025.2 qtpy : None pyqt5 : None

Comment From: rhshadrach

Thanks for the report. Further investigations are certainly welcome. If there is an adjustment pandas can make to improve this functionality and it isn't a heavy code change, then a PR is welcome as well. However I do not think we should leave issues for supporting various IDEs on the queue for the long term if there is no proposed fix. Marking as a closing candidate for now.

Comment From: iabhi4

I looked into this a bit more to see if there's a clean way to get “Go to Definition” working in VSCode (Pylance) for @register_dataframe_accessor.

After trying things like __annotations__ and TYPE_CHECKING, what actually worked was:

Creating a subclass of DataFrame with the accessor annotated:

class DataFrameWithAccessor(pd.DataFrame):
    demo: DemoAccessor

Then doing a cast before usage:

df = pd.DataFrame({...})
df = cast(DataFrameWithAccessor, df)
df.demo.say_hello()

This makes Pylance resolve the method statically without needing anything from pandas itself. Might be worth dropping a line about this in the docs or a dev tip somewhere, happy to PR it if useful.

Comment From: mroeschke

Agreed that pandas shouldn't necessarily be responsible for IDE specific feature support, so closing

Comment From: arnoldjames98

For other with this problem, here's a link to another thread with the solution that worked for me: https://github.com/microsoft/pylance-release/issues/7275.