Skip to content

BUG: VSCode go to definition doesn't work with pandas.api.extensions.register_dataframe_accessor #61510

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

Closed
2 of 3 tasks
arnoldjames98 opened this issue May 28, 2025 · 3 comments
Labels
Accessors accessor registration mechanism (not .str, .dt, .cat) Bug Closing Candidate May be closeable, needs more eyeballs

Comments

@arnoldjames98
Copy link

arnoldjames98 commented May 28, 2025

Pandas version checks

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

  • 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 : d9cdd2e
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

@arnoldjames98 arnoldjames98 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 28, 2025
@rhshadrach
Copy link
Member

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.

@rhshadrach rhshadrach added Closing Candidate May be closeable, needs more eyeballs Accessors accessor registration mechanism (not .str, .dt, .cat) and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 30, 2025
@iabhi4
Copy link
Contributor

iabhi4 commented Jun 1, 2025

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.

@mroeschke
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accessors accessor registration mechanism (not .str, .dt, .cat) Bug Closing Candidate May be closeable, needs more eyeballs
Projects
None yet
Development

No branches or pull requests

4 participants