Skip to content

The signature of pandas.ExcelFile(...) in stubs is not consistent with the run-time signature. #1116

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
cainmagi opened this issue Feb 12, 2025 · 2 comments · Fixed by #1117
Labels
IO Excel read_excel, to_excel

Comments

@cainmagi
Copy link
Contributor

cainmagi commented Feb 12, 2025

Describe the bug

In the stubs, the signature of pandas.io.excel.ExcelFile(...) in pandas==2.2.3 supposes to be

ExcelFile(
    path_or_buffer,
    engine: str | None = None,
    storage_options: StorageOptions | None = None,
    engine_kwargs: dict | None = None,
) -> None:

However, the actual implementation in stubs is

def __init__(
self,
io: FilePath | ReadBuffer[bytes] | bytes,
engine: ExcelReadEngine | None = ...,
storage_options: StorageOptions = ...,
) -> None: ...

where

  • the first argument name should be path_or_buffer, not io.
  • the keyword engine_kwargs is missing.
  • the keyword storage_options should allow a None value. Sorry, I found that None case has been included here.

To Reproduce

The following codes will work in run time, but show typing issues by Pylance:

def load_group_data(data_path):
    with ExcelFile(
        path_or_buffer=data_path,
        engine="openpyxl",
        storage_options=None,
        engine_kwargs={"read_only": True, "data_only": True}
    ) as fobj:
        pass

Pyright (with stubs) reports:

Argument missing for parameter "io"
Pylance[reportCallIssue](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportCallIssue)
No parameter named "path_or_buffer"
Pylance[reportCallIssue](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportCallIssue)
No parameter named "engine_kwargs"
Pylance[reportCallIssue](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportCallIssue)

Please complete the following information:

  • OS: Linux in Docker
  • OS Version: Debain 12
  • OS of the native device: Windows 11 Enterprise 24H2, Build 26100.3037
  • Docker image: python:3.10-slim
  • Docker Version: Docker Desktop 4.38.0 (181591)
  • python version: Python 3.10.14
  • version of type checker: Pylance language server 2025.2.1 (pyright version 1.1.393, commit 3763156f)
  • version of installed pandas-stubs: v2.2.3.241126
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Feb 12, 2025

Thanks for the report. PR with tests welcome.

It appears this was not documented in pandas prior to version 2.0, and the release notes never indicated that it became documented.

@Dr-Irv Dr-Irv added the IO Excel read_excel, to_excel label Feb 12, 2025
@cainmagi
Copy link
Contributor Author

Thank you! I will try to make a PR later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO Excel read_excel, to_excel
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants