diff --git a/pandas/io/sql.py b/pandas/io/sql.py index bb6f9cee5766e..5a778ca08b0a3 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -700,7 +700,8 @@ def _harmonize_columns(self, parse_dates=None): pass # this column not in results def _sqlalchemy_type(self, arr_or_dtype): - from sqlalchemy.types import Integer, Float, Text, Boolean, DateTime, Date, Interval + from sqlalchemy.types import (BigInteger, Float, Text, Boolean, + DateTime, Date, Interval) if arr_or_dtype is date: return Date @@ -714,12 +715,12 @@ def _sqlalchemy_type(self, arr_or_dtype): warnings.warn("the 'timedelta' type is not supported, and will be " "written as integer values (ns frequency) to the " "database.", UserWarning) - return Integer + return BigInteger elif com.is_float_dtype(arr_or_dtype): return Float elif com.is_integer_dtype(arr_or_dtype): # TODO: Refine integer size. - return Integer + return BigInteger elif com.is_bool(arr_or_dtype): return Boolean return Text diff --git a/pandas/io/tests/test_sql.py b/pandas/io/tests/test_sql.py index a34f278fc5a96..bdb609e99eb62 100644 --- a/pandas/io/tests/test_sql.py +++ b/pandas/io/tests/test_sql.py @@ -828,6 +828,14 @@ def test_default_type_conversion(self): self.assertTrue(issubclass(df.BoolColWithNull.dtype.type, np.object), "BoolColWithNull loaded with incorrect type") + def test_bigint(self): + # int64 should be converted to BigInteger, GH7433 + df = DataFrame(data={'i64':[2**62]}) + df.to_sql('test_bigint', self.conn, index=False) + result = sql.read_sql_table('test_bigint', self.conn) + + tm.assert_frame_equal(df, result) + def test_default_date_load(self): df = sql.read_sql_table("types_test_data", self.conn)