Skip to content

read_sql_*() methods have incorrect typing for dtype argument. #53046

Closed
@Dr-Irv

Description

@Dr-Irv

The read_sql() docs say for the new dtype argument:

dtype Type name or dict of columns
Data type for data or columns. E.g. np.float64 or {‘a’: np.float64, ‘b’: np.int32, ‘c’: ‘Int64’}. The argument is ignored if a table is passed instead of a query.

But in the typing in the source code, the argument is DtypeArg | None which doesn't allow something like {"c": "str"} . The implementation just passes dtype to DataFrame.astype().

See pandas-dev/pandas-stubs#676

NOTE: In pandas-stubs we did work to create all the possible strings and dtypes for astype(), so maybe that should be copied over to the pandas source??

Metadata

Metadata

Assignees

Labels

IO SQLto_sql, read_sql, read_sql_queryTypingtype annotations, mypy/pyright type checking

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions