Skip to content

BUG : Io sql one column (issue #3628) #3644

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 2 commits into from
May 19, 2013
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
6 changes: 5 additions & 1 deletion pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 12 additions & 0 deletions pandas/io/tests/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down