Repository navigation
TYP: accept a dict in pd.option_context - #2006
Merged
loicdiridollou merged 1 commit intoOct 20, 2026
Merged
Conversation
Co-authored-by: claude-opus-5-5 <noreply@anthropic.com>
loicdiridollou
approved these changes
Oct 20, 2026
loicdiridollou
left a comment
Member
There was a problem hiding this comment.
Looks good, thanks @Blacksujit
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.
assert_type()to assert the type of any return value)AGENTS.md.Adds an
option_context.__init__overload that takes a single positionaldict[str, Any], matching the documented pandas 3.0 formpd.option_context({"display.max_rows": 10}).patandvalin the pattern/value overload are now positional-only, because the runtime isoption_context(*args)and passing them by keyword raisesTypeError.AI Implementation Plan
Motivation
option_contextdocstring examplewith option_context({"display.max_rows": 10, "display.max_columns": 5})is rejected by all four checkers.Change (
pandas-stubs/_config/config.pyi)option_context.__init__is now two overloads:(self, pats: dict[str, Any], /)(self, pat: str, val: Any, /, *args: Any)(the existing signature, withpat/valnow positional-only:pd.option_context(pat="display.max_rows", val=5)raisesTypeError: option_context() got an unexpected keyword argument 'pat'at runtime)len(args) == 1 and isinstance(args[0], dict)at runtime.Tests
tests/test_config.py::test_optionsgets twowith pd.option_context({...}):blocks (one key, two keys) that assert the option is set inside the block. They follow the style of the existingoption_contexttest in the same function.pytest tests/test_config.py: 8 passed.Regression check
scripts/test/run.pysource commands, targeting Python 3.12:mypy pandas-stubs tests --no-incremental --strictpyright --warningspyrefly check pandas-stubs tests --preset strictty check pandas-stubs testsCaveats / out of scope
set_optionuses*args: dict[str, Any], which also allows several dicts. That fails at runtime foroption_context, so I didn't copy it.