@@ -383,6 +383,8 @@ def read_sql_query(
383
383
Data type for data or columns. E.g. np.float64 or
384
384
{‘a’: np.float64, ‘b’: np.int32, ‘c’: ‘Int64’}
385
385
386
+ .. versionadded:: 1.3.0
387
+
386
388
Returns
387
389
-------
388
390
DataFrame or Iterator[DataFrame]
@@ -609,7 +611,7 @@ def to_sql(
609
611
index : bool = True ,
610
612
index_label = None ,
611
613
chunksize : Optional [int ] = None ,
612
- dtype = None ,
614
+ dtype : Optional [ DtypeArg ] = None ,
613
615
method : Optional [str ] = None ,
614
616
) -> None :
615
617
"""
@@ -768,7 +770,7 @@ def __init__(
768
770
index_label = None ,
769
771
schema = None ,
770
772
keys = None ,
771
- dtype = None ,
773
+ dtype : Optional [ DtypeArg ] = None ,
772
774
):
773
775
self .name = name
774
776
self .pd_sql = pandas_sql_engine
@@ -1108,9 +1110,9 @@ def _harmonize_columns(self, parse_dates=None):
1108
1110
1109
1111
def _sqlalchemy_type (self , col ):
1110
1112
1111
- dtype = self .dtype or {}
1112
- if col .name in dtype :
1113
- return self . dtype [col .name ]
1113
+ dtype : DtypeArg = self .dtype or {}
1114
+ if isinstance ( dtype , dict ) and col .name in dtype :
1115
+ return dtype [col .name ]
1114
1116
1115
1117
# Infer type of column, while ignoring missing values.
1116
1118
# Needed for inserting typed data containing NULLs, GH 8778.
@@ -1203,7 +1205,18 @@ def read_sql(self, *args, **kwargs):
1203
1205
"connectable or sqlite connection"
1204
1206
)
1205
1207
1206
- def to_sql (self , * args , ** kwargs ):
1208
+ def to_sql (
1209
+ self ,
1210
+ frame ,
1211
+ name ,
1212
+ if_exists = "fail" ,
1213
+ index = True ,
1214
+ index_label = None ,
1215
+ schema = None ,
1216
+ chunksize = None ,
1217
+ dtype : Optional [DtypeArg ] = None ,
1218
+ method = None ,
1219
+ ):
1207
1220
raise ValueError (
1208
1221
"PandasSQL must be created with an SQLAlchemy "
1209
1222
"connectable or sqlite connection"
@@ -1430,7 +1443,7 @@ def to_sql(
1430
1443
index_label = None ,
1431
1444
schema = None ,
1432
1445
chunksize = None ,
1433
- dtype = None ,
1446
+ dtype : Optional [ DtypeArg ] = None ,
1434
1447
method = None ,
1435
1448
):
1436
1449
"""
@@ -1477,7 +1490,7 @@ def to_sql(
1477
1490
if dtype and not is_dict_like (dtype ):
1478
1491
dtype = {col_name : dtype for col_name in frame }
1479
1492
1480
- if dtype is not None :
1493
+ if dtype is not None and isinstance ( dtype , dict ) :
1481
1494
from sqlalchemy .types import TypeEngine , to_instance
1482
1495
1483
1496
for col , my_type in dtype .items ():
@@ -1563,7 +1576,7 @@ def _create_sql_schema(
1563
1576
frame : DataFrame ,
1564
1577
table_name : str ,
1565
1578
keys : Optional [List [str ]] = None ,
1566
- dtype : Optional [dict ] = None ,
1579
+ dtype : Optional [DtypeArg ] = None ,
1567
1580
schema : Optional [str ] = None ,
1568
1581
):
1569
1582
table = SQLTable (
@@ -1734,8 +1747,8 @@ def _create_table_setup(self):
1734
1747
return create_stmts
1735
1748
1736
1749
def _sql_type_name (self , col ):
1737
- dtype = self .dtype or {}
1738
- if col .name in dtype :
1750
+ dtype : DtypeArg = self .dtype or {}
1751
+ if isinstance ( dtype , dict ) and col .name in dtype :
1739
1752
return dtype [col .name ]
1740
1753
1741
1754
# Infer type of column, while ignoring missing values.
@@ -1895,7 +1908,7 @@ def to_sql(
1895
1908
index_label = None ,
1896
1909
schema = None ,
1897
1910
chunksize = None ,
1898
- dtype = None ,
1911
+ dtype : Optional [ DtypeArg ] = None ,
1899
1912
method = None ,
1900
1913
):
1901
1914
"""
@@ -1941,7 +1954,7 @@ def to_sql(
1941
1954
if dtype and not is_dict_like (dtype ):
1942
1955
dtype = {col_name : dtype for col_name in frame }
1943
1956
1944
- if dtype is not None :
1957
+ if dtype is not None and isinstance ( dtype , dict ) :
1945
1958
for col , my_type in dtype .items ():
1946
1959
if not isinstance (my_type , str ):
1947
1960
raise ValueError (f"{ col } ({ my_type } ) not a string" )
@@ -1980,7 +1993,7 @@ def _create_sql_schema(
1980
1993
frame ,
1981
1994
table_name : str ,
1982
1995
keys = None ,
1983
- dtype = None ,
1996
+ dtype : Optional [ DtypeArg ] = None ,
1984
1997
schema : Optional [str ] = None ,
1985
1998
):
1986
1999
table = SQLiteTable (
@@ -1996,7 +2009,12 @@ def _create_sql_schema(
1996
2009
1997
2010
1998
2011
def get_schema (
1999
- frame , name : str , keys = None , con = None , dtype = None , schema : Optional [str ] = None
2012
+ frame ,
2013
+ name : str ,
2014
+ keys = None ,
2015
+ con = None ,
2016
+ dtype : Optional [DtypeArg ] = None ,
2017
+ schema : Optional [str ] = None ,
2000
2018
):
2001
2019
"""
2002
2020
Get the SQL db table schema for the given frame.
0 commit comments