@@ -1160,6 +1160,45 @@ def test_sqlalchemy_type_mapping(self):
1160
1160
# GH 9086: TIMESTAMP is the suggested type for datetimes with timezones
1161
1161
assert isinstance (table .table .c ["time" ].type , sqltypes .TIMESTAMP )
1162
1162
1163
+ @pytest .mark .parametrize (
1164
+ "integer, expected" ,
1165
+ [
1166
+ ("int8" , "SMALLINT" ),
1167
+ ("Int8" , "SMALLINT" ),
1168
+ ("uint8" , "SMALLINT" ),
1169
+ ("UInt8" , "SMALLINT" ),
1170
+ ("int16" , "SMALLINT" ),
1171
+ ("Int16" , "SMALLINT" ),
1172
+ ("uint16" , "INTEGER" ),
1173
+ ("UInt16" , "INTEGER" ),
1174
+ ("int32" , "INTEGER" ),
1175
+ ("Int32" , "INTEGER" ),
1176
+ ("uint32" , "BIGINT" ),
1177
+ ("UInt32" , "BIGINT" ),
1178
+ ("int64" , "BIGINT" ),
1179
+ ("Int64" , "BIGINT" ),
1180
+ (int , "BIGINT" if np .dtype (int ).name == "int64" else "INTEGER" ),
1181
+ ],
1182
+ )
1183
+ def test_sqlalchemy_integer_mapping (self , integer , expected ):
1184
+ # GH35076 Map pandas integer to optimal SQLAlchemy integer type
1185
+ df = DataFrame ([0 , 1 ], columns = ["a" ], dtype = integer )
1186
+ db = sql .SQLDatabase (self .conn )
1187
+ table = sql .SQLTable ("test_type" , db , frame = df )
1188
+
1189
+ result = str (table .table .c .a .type )
1190
+ assert result == expected
1191
+
1192
+ @pytest .mark .parametrize ("integer" , ["uint64" , "UInt64" ])
1193
+ def test_sqlalchemy_integer_overload_mapping (self , integer ):
1194
+ # GH35076 Map pandas integer to optimal SQLAlchemy integer type
1195
+ df = DataFrame ([0 , 1 ], columns = ["a" ], dtype = integer )
1196
+ db = sql .SQLDatabase (self .conn )
1197
+ with pytest .raises (
1198
+ ValueError , match = "Unsigned 64 bit integer datatype is not supported"
1199
+ ):
1200
+ sql .SQLTable ("test_type" , db , frame = df )
1201
+
1163
1202
def test_database_uri_string (self ):
1164
1203
1165
1204
# Test read_sql and .to_sql method with a database URI (GH10654)
0 commit comments