Closed
Description
Describe the bug
The DataFrame.sample function has an argument called axis
that accepts either of the axis, but the type only allows 'index' or 0
.
To Reproduce
- Provide a minimal runnable
pandas
example that is not properly checked by the stubs.
df = pd.DataFrame({1: [2,3], 4: [5,6]})
df.sample(n=1, axis=1)
- Indicate which type checker you are using (
mypy
orpyright
):
Pylance in Visual Studio Code
- Show the error message received from that type checker while checking your example.
Argument of type "Literal[1]" cannot be assigned to parameter "axis" of type "AxisIndex | None" in function "sample"
Type "Literal[1]" is not assignable to type "AxisIndex | None"
"Literal[1]" is not assignable to "None"
"Literal[1]" is not assignable to "Literal['index']"
"Literal[1]" is not assignable to type "Literal[0]"

Please complete the following information:
- OS: MacOS
- OS Version: 15.5
- python version: 3.13.3
- version of type checker: vscode-pylance-2025.6.1
- version of installed
pandas-stubs
: 2.2.3.250527
Additional context
Add any other context about the problem here.
Pandas Docs showing the type of the axis
argument: https://pandas.pydata.org/docs/dev/reference/api/pandas.DataFrame.sample.html
