Skip to content

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

Closed
@cainmagi

Description

@cainmagi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO Excelread_excel, to_excel

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions