diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 3002f2f620f5e..b54a30d95bb54 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -228,7 +228,11 @@ def _write_sqlite(frame, table, names, cur): wildcards = ','.join(['?'] * len(names)) insert_query = 'INSERT INTO %s (%s) VALUES (%s)' % ( table, col_names, wildcards) - data = [tuple(x) for x in frame.values] + # pandas types are badly handled if there is only 1 column ( Issue #3628 ) + if not len(frame.columns )==1 : + data = [tuple(x) for x in frame.values] + else : + data = [tuple(x) for x in frame.values.tolist()] cur.executemany(insert_query, data) def _write_mysql(frame, table, names, cur): diff --git a/pandas/io/tests/test_sql.py b/pandas/io/tests/test_sql.py index b443c55f97b8d..1daa50c70a900 100644 --- a/pandas/io/tests/test_sql.py +++ b/pandas/io/tests/test_sql.py @@ -219,6 +219,18 @@ def test_keyword_as_column_names(self): df = DataFrame({'From':np.ones(5)}) sql.write_frame(df, con = self.db, name = 'testkeywords') + def test_onecolumn_of_integer(self): + ''' + a column_of_integers dataframe should transfer well to sql + ''' + mono_df=DataFrame([1 , 2], columns=['c0']) + sql.write_frame(mono_df, con = self.db, name = 'mono_df') + # computing the sum via sql + con_x=self.db + the_sum=sum([my_c0[0] for my_c0 in con_x.execute("select * from mono_df")]) + # it should not fail, and gives 3 ( Issue #3628 ) + self.assertEqual(the_sum , 3) + class TestMySQL(unittest.TestCase):