The pandas-stubs project is introduced in README.md.
- Assist contributors by suggesting code changes, tests, and documentation edits for the
pandas-stubsrepository while preserving stability and compatibility.
- Concise, neutral, code-focused. Prioritize correctness, readability, and tests.
- Follow
docs/philosophy.md. - Also follow all guidelines for contributing to the codebase specified at Contributing to the code base.
- Favor small, backward-compatible changes with tests.
- Prefer readability over micro-optimizations unless benchmarks are requested.
- Add tests for behavioral changes.
- When referring to GitHub issues and pull requests, use the short format
pandas-dev/pandas#39196instead of full URLs likehttps://github.com/pandas-dev/pandas/issues/39196 - If new code is clear from naming and references, do not add detailed comments. Keep code self-documenting.
CRITICAL: This project prioritizes static type checking over runtime error testing. When designing stubs and tests:
When an error is expected to raise (invalid operations):
- Design stubs to return
Neveror cause type checker errors for invalid usage - In tests, protect invalid operations with
if TYPE_CHECKING_INVALID_USAGE:instead ofwith pytest.raises(...) - Add
# type: ignore[<error-code>]and/or# pyright: ignore[<error-code>]comments to verify type checkers catch the error
Example (from docs/philosophy.md):
i1 = pd.Interval(
pd.Timestamp("2000-01-01"), pd.Timestamp("2000-01-03"), closed="both"
)
if TYPE_CHECKING_INVALID_USAGE:
_0 = i1 + pd.Timestamp("2000-03-03") # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]Why: The goal is to catch errors at type-check time, not runtime. The TYPE_CHECKING_INVALID_USAGE guard (which is False at runtime) prevents runtime execution while the ignore comments verify type checkers properly reject the invalid code.
Incorrect pattern:
with pytest.raises(TypeError):
s1 + s2 # adding two timestampsCorrect pattern:
if TYPE_CHECKING_INVALID_USAGE:
_0 = s1 + s2 # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]When testing operations, assign the result to a dummy variable (e.g., _0, _1, etc.) to avoid ruff's useless-comparison rule:
if TYPE_CHECKING_INVALID_USAGE:
_0 = a > b # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]This applies to any expression that would trigger warnings about unused results (comparisons, arithmetic operations, etc.).
See docs/philosophy.md sections "Testing the Type Stubs" and "Narrow vs. Wide Arguments" for full details.
REQUIRED: After editing stubs or tests, run the following command to validate your changes:
poetry run poe test_allAll checks must pass before submitting changes. These commands verify:
- Type stubs are correctly annotated (mypy, pyright, pyrefly)
- Invalid usage is properly rejected by type checkers (ty)
- Tests execute successfully at runtime (test)
- Pull request titles should be descriptive and include one of the following prefixes:
- ENH: Enhancement, new functionality
- BUG: Bug fix
- DOC: Additions/updates to documentation
- TST: Additions/updates to tests
- BLD: Updates to the build process/scripts
- PERF: Performance improvement
- TYP: Type annotations
- CLN: Code cleanup
- Pull request descriptions should follow the template, and succinctly describe the change being made. Usually a few sentences is sufficient.
- Pull requests which are resolving an existing Github Issue should include a link to the issue in the PR Description.
- Do not add summaries or additional comments to individual commit messages. The single PR description is sufficient.