Skip to content

Commit f6a5f41

Browse files
Merge pull request #7634 from jorisvandenbossche/sql-int64
FIX: don't create 32 bit int type for int64 column (GH7433)
2 parents 55248f3 + d94cf76 commit f6a5f41

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

pandas/io/sql.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,8 @@ def _harmonize_columns(self, parse_dates=None):
700700
pass # this column not in results
701701

702702
def _sqlalchemy_type(self, arr_or_dtype):
703-
from sqlalchemy.types import Integer, Float, Text, Boolean, DateTime, Date, Interval
703+
from sqlalchemy.types import (BigInteger, Float, Text, Boolean,
704+
DateTime, Date, Interval)
704705

705706
if arr_or_dtype is date:
706707
return Date
@@ -714,12 +715,12 @@ def _sqlalchemy_type(self, arr_or_dtype):
714715
warnings.warn("the 'timedelta' type is not supported, and will be "
715716
"written as integer values (ns frequency) to the "
716717
"database.", UserWarning)
717-
return Integer
718+
return BigInteger
718719
elif com.is_float_dtype(arr_or_dtype):
719720
return Float
720721
elif com.is_integer_dtype(arr_or_dtype):
721722
# TODO: Refine integer size.
722-
return Integer
723+
return BigInteger
723724
elif com.is_bool(arr_or_dtype):
724725
return Boolean
725726
return Text

pandas/io/tests/test_sql.py

+8
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,14 @@ def test_default_type_conversion(self):
829829
self.assertTrue(issubclass(df.BoolColWithNull.dtype.type, np.object),
830830
"BoolColWithNull loaded with incorrect type")
831831

832+
def test_bigint(self):
833+
# int64 should be converted to BigInteger, GH7433
834+
df = DataFrame(data={'i64':[2**62]})
835+
df.to_sql('test_bigint', self.conn, index=False)
836+
result = sql.read_sql_table('test_bigint', self.conn)
837+
838+
tm.assert_frame_equal(df, result)
839+
832840
def test_default_date_load(self):
833841
df = sql.read_sql_table("types_test_data", self.conn)
834842

0 commit comments

Comments
 (0)