Skip to content

Conversation

Sachi-Parashar
Copy link
Contributor

Summary

This PR addresses issue #849, where pyright fails to type-check the converters argument in read_excel when using functools.partial or lambda functions.

Fix

Updated all read_excel and parse overloads in pandas/io/excel/_base.pyi:

- converters: Mapping[int | str, Callable[[object], object]] | None
+ converters: Mapping[int | str, Callable[[Any], Any]] | None

This relaxes the type signature to accept functools.partial and similar callables.

Test

Added a test tests/test_excel_converters.py with assert_type to confirm the fix works with pyright and mypy.

from functools import partial
import pandas as pd
from typing_extensions import assert_type

conv = partial(pd.to_datetime, errors="coerce")
df = pd.read_excel("foo.xlsx", converters={"col1": conv})
assert_type(df, pd.DataFrame)

Notes

  • Verified with both mypy and pyright. - Worked✅
  • If needed, I'm open to updating ConvertersArg in _typing.pyi for broader consistency in a follow-up PR.

Closes #849

@Sachi-Parashar Sachi-Parashar changed the title Add files via upload Fix #849: Update converters type in read_excel for better Pyright compatibility Jul 28, 2025
Remove redundant test_excel_converters.py after moving test to test_io.py
Add test_converters_partial() to test_io.py for read_excel converters
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dr-Irv Dr-Irv merged commit 2f63354 into pandas-dev:main Sep 19, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type checking with converters= on read_excel
3 participants