Skip to content

DataFrame.sample argument 'axis' should accept any Axis #1251

Closed
@nithinmanne

Description

@nithinmanne

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

  1. 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)
  1. Indicate which type checker you are using (mypy or pyright):
Pylance in Visual Studio Code
  1. 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]"
Image

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

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions