Skip to content

Commit 47d2ce4

Browse files
ramvikramsDr-Irv
andauthored
GH-676 : Corrected DtypeArg for accepting strings (#680)
* GH-676 * Update test_io.py * Update tests/test_io.py Co-authored-by: Irv Lustig <[email protected]> * Update test_io.py --------- Co-authored-by: Irv Lustig <[email protected]>
1 parent 56d58e2 commit 47d2ce4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pandas-stubs/_typing.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class FulldatetimeDict(YearMonthDayDict, total=False):
7676
# dtypes
7777
NpDtype: TypeAlias = str | np.dtype[np.generic] | type[str | complex | bool | object]
7878
Dtype: TypeAlias = ExtensionDtype | NpDtype
79-
DtypeArg: TypeAlias = Dtype | dict[Any, Dtype]
79+
DtypeArg: TypeAlias = Dtype | Mapping[Any, Dtype]
8080
DtypeBackend: TypeAlias = Literal["pyarrow", "numpy_nullable"]
8181
BooleanDtypeArg: TypeAlias = (
8282
# Builtin bool type and its string alias

tests/test_io.py

+20
Original file line numberDiff line numberDiff line change
@@ -1388,3 +1388,23 @@ def test_read_with_lxml_dtype_backend() -> None:
13881388
check(
13891389
assert_type(read_xml(path, dtype_backend="pyarrow"), DataFrame), DataFrame
13901390
)
1391+
1392+
1393+
def test_read_sql_dict_str_value_dtype() -> None:
1394+
# GH 676
1395+
with ensure_clean() as path:
1396+
con = sqlite3.connect(path)
1397+
check(assert_type(DF.to_sql("test", con), Union[int, None]), int)
1398+
check(
1399+
assert_type(
1400+
read_sql_query(
1401+
"select * from test",
1402+
con=con,
1403+
index_col="index",
1404+
dtype={"a": "int"},
1405+
),
1406+
DataFrame,
1407+
),
1408+
DataFrame,
1409+
)
1410+
con.close()

0 commit comments

Comments
 (0)