Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nithinmanne opened this issue Jun 16, 2025 · 2 comments · Fixed by #1252
Closed

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

nithinmanne opened this issue Jun 16, 2025 · 2 comments · Fixed by #1252

Comments

@nithinmanne
Copy link
Contributor

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
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jun 16, 2025

Thanks for the report. PR with tests welcome.

@nithinmanne
Copy link
Contributor Author

Thanks for the report. PR with tests welcome.

Thanks, I added a PR too: #1252
Its a small change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants