Skip to content

Commit 3355333

Browse files
committed
Fix sql params type
1 parent 89e083b commit 3355333

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

pandas-stubs/io/sql.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from collections.abc import (
22
Callable,
33
Generator,
44
Iterable,
5+
Mapping,
56
)
67
import sqlite3
78
from typing import (
@@ -65,7 +66,7 @@ def read_sql_query(
6566
con: _SQLConnection,
6667
index_col: str | list[str] | None = ...,
6768
coerce_float: bool = ...,
68-
params: list[str] | tuple[str, ...] | dict[str, str] | None = ...,
69+
params: list[Any] | tuple[Any, ...] | Mapping[str, Any] | None = ...,
6970
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ...,
7071
*,
7172
chunksize: int,
@@ -78,7 +79,7 @@ def read_sql_query(
7879
con: _SQLConnection,
7980
index_col: str | list[str] | None = ...,
8081
coerce_float: bool = ...,
81-
params: list[str] | tuple[str, ...] | dict[str, str] | None = ...,
82+
params: list[Any] | tuple[Any, ...] | Mapping[str, Any] | None = ...,
8283
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ...,
8384
chunksize: None = ...,
8485
dtype: DtypeArg | None = ...,
@@ -90,7 +91,7 @@ def read_sql(
9091
con: _SQLConnection,
9192
index_col: str | list[str] | None = ...,
9293
coerce_float: bool = ...,
93-
params: list[str] | tuple[str, ...] | dict[str, str] | None = ...,
94+
params: list[Any] | tuple[Any, ...] | Mapping[str, Any] | None = ...,
9495
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ...,
9596
columns: list[str] = ...,
9697
*,
@@ -104,7 +105,7 @@ def read_sql(
104105
con: _SQLConnection,
105106
index_col: str | list[str] | None = ...,
106107
coerce_float: bool = ...,
107-
params: list[str] | tuple[str, ...] | dict[str, str] | None = ...,
108+
params: list[Any] | tuple[Any, ...] | Mapping[str, Any] | None = ...,
108109
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ...,
109110
columns: list[str] = ...,
110111
chunksize: None = ...,

tests/test_io.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,26 @@ def test_read_sql_via_sqlalchemy_engine():
11411141
engine.dispose()
11421142

11431143

1144+
def test_read_sql_via_sqlalchemy_engine_with_params():
1145+
with ensure_clean() as path:
1146+
db_uri = "sqlite:///" + path
1147+
engine = sqlalchemy.create_engine(db_uri)
1148+
1149+
check(assert_type(DF.to_sql("test", con=engine), Union[int, None]), int)
1150+
check(
1151+
assert_type(
1152+
read_sql(
1153+
"select * from test where a = :a and b = :b",
1154+
con=engine,
1155+
params={"a": 2, "b": 0.0},
1156+
),
1157+
DataFrame,
1158+
),
1159+
DataFrame,
1160+
)
1161+
engine.dispose()
1162+
1163+
11441164
def test_read_sql_generator():
11451165
with ensure_clean() as path:
11461166
con = sqlite3.connect(path)
@@ -1200,6 +1220,26 @@ def test_read_sql_query_generator():
12001220
con.close()
12011221

12021222

1223+
def test_read_sql_query_via_sqlalchemy_engine_with_params():
1224+
with ensure_clean() as path:
1225+
db_uri = "sqlite:///" + path
1226+
engine = sqlalchemy.create_engine(db_uri)
1227+
1228+
check(assert_type(DF.to_sql("test", con=engine), Union[int, None]), int)
1229+
check(
1230+
assert_type(
1231+
read_sql_query(
1232+
"select * from test where a = :a and b = :b",
1233+
con=engine,
1234+
params={"a": 2, "b": 0.0},
1235+
),
1236+
DataFrame,
1237+
),
1238+
DataFrame,
1239+
)
1240+
engine.dispose()
1241+
1242+
12031243
def test_read_html():
12041244
check(assert_type(DF.to_html(), str), str)
12051245
with ensure_clean() as path:

0 commit comments

Comments
 (0)