Skip to content

Commit d0efd0f

Browse files
SNOW-642562-yuwang: cursor.fetch_pandas_batches() when executing asynchronously (#1222)
1 parent 9393302 commit d0efd0f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/snowflake/connector/cursor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,7 @@ def fetch_pandas_batches(self, **kwargs) -> Iterator[pandas.DataFrame]:
970970
self.check_can_use_pandas()
971971
if self._prefetch_hook is not None:
972972
self._prefetch_hook()
973+
if self._query_result_format != "arrow":
973974
raise NotSupportedError
974975
self._log_telemetry_job_data(
975976
TelemetryField.PANDAS_FETCH_BATCHES, TelemetryData.TRUE

test/integ/pandas/test_arrow_pandas.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,24 @@ def test_number_fetchbatches_retrieve_type(conn_cnx, use_decimal: bool, expected
964964
)
965965

966966

967+
def test_execute_async_and_fetch_pandas_batches(conn_cnx):
968+
"""Test get pandas in an asynchronous way"""
969+
970+
with conn_cnx() as cnx:
971+
with cnx.cursor() as cur:
972+
cur.execute("select 1/2")
973+
res_sync = cur.fetch_pandas_batches()
974+
975+
result = cur.execute_async("select 1/2")
976+
cur.get_results_from_sfqid(result["queryId"])
977+
res_async = cur.fetch_pandas_batches()
978+
979+
assert res_sync is not None
980+
assert res_async is not None
981+
for r_sync, r_async in zip(res_sync, res_async):
982+
assert r_sync.values == r_async.values
983+
984+
967985
def test_simple_async_arrow(conn_cnx):
968986
"""Simple test to that shows the most simple usage of fire and forget.
969987

0 commit comments

Comments
 (0)