Skip to content

Commit

Permalink
Merge pull request #11861 from grahamjeffries/bugfix-11522
Browse files Browse the repository at this point in the history
BUG: force list type for tuples from chunked sql table reads #11522
  • Loading branch information
jorisvandenbossche committed Dec 19, 2015
2 parents 4b19c3e + 3aea012 commit 1357321
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.18.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,4 @@ Bug Fixes
- Bug in ``Index`` prevents copying name of passed ``Index``, when a new name is not provided (:issue:`11193`)

- Bug in ``read_excel`` failing to read any non-empty sheets when empty sheets exist and ``sheetname=None`` (:issue:`11711`)
- Bug in ``read_sql`` with pymysql connections failing to return chunked data (:issue:`11522`)
2 changes: 2 additions & 0 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,8 @@ def _query_iterator(cursor, chunksize, columns, index_col=None,

while True:
data = cursor.fetchmany(chunksize)
if type(data) == tuple:
data = list(data)
if not data:
cursor.close()
break
Expand Down
15 changes: 15 additions & 0 deletions pandas/io/tests/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2477,6 +2477,21 @@ def test_write_row_by_row(self):
result.index = frame.index
tm.assert_frame_equal(result, frame)

def test_chunksize_read_type(self):
_skip_if_no_pymysql()
frame = tm.makeTimeDataFrame()
frame.index.name = "index"
drop_sql = "DROP TABLE IF EXISTS test"
cur = self.conn.cursor()
cur.execute(drop_sql)
sql.to_sql(frame, name='test', con=self.conn, flavor='mysql')
query = "select * from test"
chunksize = 5
chunk_gen = pd.read_sql_query(sql=query, con=self.conn,
chunksize=chunksize, index_col="index")
chunk_df = next(chunk_gen)
tm.assert_frame_equal(frame[:chunksize], chunk_df)

def test_execute(self):
_skip_if_no_pymysql()
frame = tm.makeTimeDataFrame()
Expand Down

0 comments on commit 1357321

Please sign in to comment.