Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pandas-stubs/io/sql.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def read_sql(
columns: list[str] = ...,
*,
chunksize: int,
dtype: DtypeArg | None = ...,
) -> Generator[DataFrame, None, None]: ...
@overload
def read_sql(
Expand All @@ -95,6 +96,7 @@ def read_sql(
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ...,
columns: list[str] = ...,
chunksize: None = ...,
dtype: DtypeArg | None = ...,
) -> DataFrame: ...

class PandasSQL(PandasObject):
Expand Down
22 changes: 22 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,3 +1204,25 @@ def test_sqlalchemy_text() -> None:
assert_type(read_sql(sql_select, con=conn), DataFrame),
DataFrame,
)


def test_read_sql_dtype() -> None:
with ensure_clean() as path:
conn = sqlite3.connect(path)
df = pd.DataFrame(
data=[[0, "10/11/12"], [1, "12/11/10"]],
columns=["int_column", "date_column"],
)
check(assert_type(df.to_sql("test_data", con=conn), Union[int, None]), int)
check(
assert_type(
pd.read_sql(
"SELECT int_column, date_column FROM test_data",
con=conn,
dtype=None,
),
pd.DataFrame,
),
pd.DataFrame,
)
conn.close()