PERF: speed up tab completion for DataFrame/Series with a large index#65277
Open
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
Open
PERF: speed up tab completion for DataFrame/Series with a large index#65277jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
Conversation
… (GH#18587) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm on the fence as to whether this is a big enough deal to merit special-casing.
Summary
_dir_additions_for_ownerwhen only the firstdisplay.max_dir_itemsunique values are needed. First try a bounded prefix (max_items * 10); fall back to fullunique()only when the prefix is duplicate-heavy, so behavior is preserved for pathological sorted-duplicate cases (e.g.MultiIndexlevel 0).dir(df)for a DataFrame with 1M unique string columns goes from ~115 ms to ~17 ms on my machine. Non-unique and sorted-duplicate cases are unchanged.Dirbenchmark (cold path vianumber=1+_cache={}) and a whatsnew entry.Test plan
pytest pandas/tests/frame/test_api.py pandas/tests/series/test_api.py pandas/tests/indexes/test_base.pytest_display_max_dir_itemscovers the default cap, a custom cap, andNone(unlimited)pre-commit runon the changed files🤖 Generated with Claude Code