Open FakeNameSE opened 2 weeks ago
Thanks for the report!
This problem is not always visible because the corresponding
pandas-stubs
already does this. The inconsistency appears however in some type checkers when additional stubs are not available or configured though.
It seems to me this is not appropriate. PEP 561 makes this quite clear I think:
Package maintainers who wish to support type checking of their code MUST add a marker file named py.typed to their package supporting typing.
Since pandas does not have a py.typed
file, its type-hints should not be considered public. I only mention this to say that I think pandas should not be obligated to spend unnecessary effort in order to support third parties that use its internal type-hints.
Of course, in cases where the change would benefit pandas internal typing (as is the case here I believe), PRs are welcome!
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
The pandas type annotations for the
parse_dates
argument inread_sql_table()
andread_sql_query()
is overly restrictive. It incorrectly causes type checkers to complain when using theparse_dates
argument to pass keyword arguments toto_datetime()
as documented here.To solve this problem, the annotated type for
parse_date
just needs to be switched fromparse_dates: list[str] | dict[str, str] | None
tolist[str] | dict[str, str] | dict[str, dict[str, Any]] | None
.This problem is not always visible because the corresponding
pandas-stubs
already does this. The inconsistency appears however in some type checkers when additional stubs are not available or configured though.To illustrate, take the provided (valid) example and run
pyright
on it (with no arguments). It will output the following.I am more than happy to submit a pull request for this is desired, but thought it best to put in this issue first in case I am missing something.
Expected Behavior
import pandas as pd import sqlite3
date_params = {"date_col": {"utc": True}}
with sqlite3.connect("blah") as con:
Type checks correctly
Installed Versions