Skip to content

FIX: don't create 32 bit int type for int64 column (GH7433) #7634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pandas/io/tests/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down