-
-
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?
Changes from all commits
a0614f3
ae5365d
2c1b5df
288c04d
19d18ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
) | ||
|
||
import numpy as np | ||
from functools import partial | ||
import pandas as pd | ||
from pandas import ( | ||
DataFrame, | ||
|
@@ -304,23 +305,23 @@ def test_sas_bdat() -> None: | |
path = pathlib.Path(CWD, "data", "airline.sas7bdat") | ||
check(assert_type(read_sas(path), DataFrame), DataFrame) | ||
with check( | ||
assert_type(read_sas(path, iterator=True), Union[SAS7BDATReader, XportReader]), | ||
SAS7BDATReader, | ||
assert_type(read_sas(path, iterator=True), Union[SAS7BDATReader, XportReader]), | ||
SAS7BDATReader, | ||
Comment on lines
+308
to
+309
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
): | ||
pass | ||
with check( | ||
assert_type(read_sas(path, iterator=True, format="sas7bdat"), SAS7BDATReader), | ||
SAS7BDATReader, | ||
assert_type(read_sas(path, iterator=True, format="sas7bdat"), SAS7BDATReader), | ||
SAS7BDATReader, | ||
): | ||
pass | ||
with check( | ||
assert_type(read_sas(path, chunksize=1), Union[SAS7BDATReader, XportReader]), | ||
SAS7BDATReader, | ||
assert_type(read_sas(path, chunksize=1), Union[SAS7BDATReader, XportReader]), | ||
SAS7BDATReader, | ||
): | ||
pass | ||
with check( | ||
assert_type(read_sas(path, chunksize=1, format="sas7bdat"), SAS7BDATReader), | ||
SAS7BDATReader, | ||
assert_type(read_sas(path, chunksize=1, format="sas7bdat"), SAS7BDATReader), | ||
SAS7BDATReader, | ||
): | ||
pass | ||
|
||
|
@@ -329,23 +330,23 @@ def test_sas_xport() -> None: | |
path = pathlib.Path(CWD, "data", "SSHSV1_A.xpt") | ||
check(assert_type(read_sas(path), DataFrame), DataFrame) | ||
with check( | ||
assert_type(read_sas(path, iterator=True), Union[SAS7BDATReader, XportReader]), | ||
XportReader, | ||
assert_type(read_sas(path, iterator=True), Union[SAS7BDATReader, XportReader]), | ||
XportReader, | ||
): | ||
pass | ||
with check( | ||
assert_type(read_sas(path, iterator=True, format="xport"), XportReader), | ||
XportReader, | ||
assert_type(read_sas(path, iterator=True, format="xport"), XportReader), | ||
XportReader, | ||
): | ||
pass | ||
with check( | ||
assert_type(read_sas(path, chunksize=1), Union[SAS7BDATReader, XportReader]), | ||
XportReader, | ||
assert_type(read_sas(path, chunksize=1), Union[SAS7BDATReader, XportReader]), | ||
XportReader, | ||
): | ||
pass | ||
with check( | ||
assert_type(read_sas(path, chunksize=1, format="xport"), XportReader), | ||
XportReader, | ||
assert_type(read_sas(path, chunksize=1, format="xport"), XportReader), | ||
XportReader, | ||
): | ||
pass | ||
|
||
|
@@ -1149,9 +1150,9 @@ def test_excel_reader(): | |
check(assert_type(pd.read_excel(ef), pd.DataFrame), pd.DataFrame) | ||
|
||
with pd.ExcelFile( | ||
path_or_buffer=path, | ||
engine="openpyxl", | ||
engine_kwargs={"data_only": True}, | ||
path_or_buffer=path, | ||
engine="openpyxl", | ||
engine_kwargs={"data_only": True}, | ||
) as ef: | ||
check(assert_type(ef, pd.ExcelFile), pd.ExcelFile) | ||
check(assert_type(pd.read_excel(ef), pd.DataFrame), pd.DataFrame) | ||
|
@@ -1792,3 +1793,15 @@ def test_read_json_engine() -> None: | |
pd.read_json(dd, lines=False, engine="pyarrow") # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] | ||
pd.read_json(io.StringIO(data), engine="pyarrow") # type: ignore[call-overload] # pyright: ignore[reportArgumentType] | ||
pd.read_json(io.StringIO(data), lines=True, engine="pyarrow") # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] | ||
|
||
|
||
def test_converters_partial() -> None: | ||
df = pd.DataFrame({"field_1": ["2020-01-01", "not a date"]}) | ||
partial_func = partial(pd.to_datetime, errors="coerce") | ||
|
||
with ensure_clean(".xlsx") as path: | ||
check(assert_type(df.to_excel(path, index=False), None), type(None)) | ||
|
||
result = pd.read_excel(path, converters={"field_1": partial_func}) | ||
check(assert_type(result, pd.DataFrame), pd.DataFrame) | ||
|
Uh oh!
There was an error while loading. Please reload this page.