Skip to content

Commit 2a64bc1

Browse files
BUG: Fixes GH34411
pd.read_sql now returns a list with an empty pd.DataFrame if chunksize is greater than 0 and the query returns 0 results.
1 parent bd469a0 commit 2a64bc1

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

pandas/io/sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ def _query_iterator(
12451245
columns,
12461246
index_col=index_col,
12471247
coerce_float=coerce_float,
1248-
parse_dates=parse_dates
1248+
parse_dates=parse_dates,
12491249
)
12501250
break
12511251
else:

pandas/tests/io/test_sql.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,13 @@ def test_read_sql_view(self):
602602
self._check_iris_loaded_frame(iris_frame)
603603

604604
def test_read_sql_with_chunksize_no_result(self):
605-
with_batch = sql.read_sql_query("SELECT * FROM iris_view WHERE SepalLength < 0.0", self.conn, chunksize=5)
606-
without_batch = sql.read_sql_query("SELECT * FROM iris_view WHERE SepalLength < 0.0", self.conn)
607-
tm.assert_frame_equal(
608-
pd.concat(with_batch),
609-
without_batch
605+
with_batch = sql.read_sql_query(
606+
"SELECT * FROM iris_view WHERE SepalLength < 0.0", self.conn, chunksize=5
610607
)
608+
without_batch = sql.read_sql_query(
609+
"SELECT * FROM iris_view WHERE SepalLength < 0.0", self.conn
610+
)
611+
tm.assert_frame_equal(pd.concat(with_batch), without_batch)
611612

612613
def test_to_sql(self):
613614
sql.to_sql(self.test_frame1, "test_frame1", self.conn)

0 commit comments

Comments
 (0)