@@ -1139,6 +1139,45 @@ def test_sqlalchemy_type_mapping(self):
1139
1139
# GH 9086: TIMESTAMP is the suggested type for datetimes with timezones
1140
1140
assert isinstance (table .table .c ["time" ].type , sqltypes .TIMESTAMP )
1141
1141
1142
+ @pytest .mark .parametrize (
1143
+ "integer, expected" ,
1144
+ [
1145
+ ("int8" , "SMALLINT" ),
1146
+ ("Int8" , "SMALLINT" ),
1147
+ ("uint8" , "SMALLINT" ),
1148
+ ("UInt8" , "SMALLINT" ),
1149
+ ("int16" , "SMALLINT" ),
1150
+ ("Int16" , "SMALLINT" ),
1151
+ ("uint16" , "INTEGER" ),
1152
+ ("UInt16" , "INTEGER" ),
1153
+ ("int32" , "INTEGER" ),
1154
+ ("Int32" , "INTEGER" ),
1155
+ ("uint32" , "BIGINT" ),
1156
+ ("UInt32" , "BIGINT" ),
1157
+ (int , "BIGINT" ),
1158
+ ("int64" , "BIGINT" ),
1159
+ ("Int64" , "BIGINT" ),
1160
+ ],
1161
+ )
1162
+ def test_sqlalchemy_integer_mapping (self , integer , expected ):
1163
+ # GH35076 Map pandas integer to optimal SQLAlchemy integer type
1164
+ df = DataFrame ([0 , 1 ], columns = ["a" ], dtype = integer )
1165
+ db = sql .SQLDatabase (self .conn )
1166
+ table = sql .SQLTable ("test_type" , db , frame = df )
1167
+
1168
+ result = str (table .table .c ["a" ].type )
1169
+ assert result == expected
1170
+
1171
+ @pytest .mark .parametrize ("integer" , ["uint64" , "UInt64" ])
1172
+ def test_sqlalchemy_integer_overload_mapping (self , integer ):
1173
+ # GH35076 Map pandas integer to optimal SQLAlchemy integer type
1174
+ df = DataFrame ([0 , 1 ], columns = ["a" ], dtype = integer )
1175
+ db = sql .SQLDatabase (self .conn )
1176
+ with pytest .raises (
1177
+ ValueError , match = "Unsigned 64 bit integer datatype is not supported"
1178
+ ):
1179
+ sql .SQLTable ("test_type" , db , frame = df )
1180
+
1142
1181
def test_database_uri_string (self ):
1143
1182
1144
1183
# Test read_sql and .to_sql method with a database URI (GH10654)
0 commit comments