-
-
Notifications
You must be signed in to change notification settings - Fork 145
Fix #849: Update converters type in read_excel for better Pyright compatibility #1297
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
base: main
Are you sure you want to change the base?
Fix #849: Update converters type in read_excel for better Pyright compatibility #1297
Conversation
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
tests/test_io.py
Outdated
|
||
partial_func = partial(pd.to_datetime, errors="coerce") | ||
df = pd.read_excel("foo.xlsx", converters={"field_1": partial_func}) | ||
assert_type(df, pd.DataFrame) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use check(assert_type(df, pd.DataFrame), pd.DataFrame)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used check(assert_type(df, pd.DataFrame), pd.DataFrame) as suggested.
assert_type(read_sas(path, iterator=True), Union[SAS7BDATReader, XportReader]), | ||
SAS7BDATReader, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why you indented here and elsewhere. Make sure to install the pre-commit
and run black
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can see from the CI that the pre-commit failed because of this
Summary
This PR addresses issue #849, where
pyright
fails to type-check theconverters
argument inread_excel
when usingfunctools.partial
or lambda functions.Fix
Updated all
read_excel
andparse
overloads inpandas/io/excel/_base.pyi
: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.
Notes
Closes #849