Skip to content

Commit e145e62

Browse files
Revert "SNOW-641540 Fix dtypes of fetch_pandas_all for empty result" (#1237)
This reverts commit 128dd75.
1 parent 128dd75 commit e145e62

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

src/snowflake/connector/result_batch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ def _get_arrow_iter(
646646
return self._create_iter(iter_unit=IterUnit.TABLE_UNIT, connection=connection)
647647

648648
def _create_empty_table(self) -> Table:
649-
"""Returns empty Arrow table based on schema"""
649+
"""Returns emtpy Arrow table based on schema"""
650650
if installed_pandas:
651651
# initialize pyarrow type array corresponding to FIELD_TYPES
652652
FIELD_TYPE_TO_PA_TYPE = [e.pa_type() for e in FIELD_TYPES]

src/snowflake/connector/result_set.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ def _fetch_pandas_all(self, **kwargs) -> pandas.DataFrame:
189189
ignore_index=True, # Don't keep in result batch indexes
190190
**kwargs,
191191
)
192-
# Empty dataframe
193-
return self.batches[0].to_pandas()
192+
return pandas.DataFrame(columns=self.batches[0].column_names)
194193

195194
def _get_metrics(self) -> dict[str, int]:
196195
"""Sum up all the chunks' metrics and show them together."""

test/integ/pandas/test_arrow_pandas.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,18 +1169,6 @@ def assert_dtype_equal(a, b):
11691169
)
11701170

11711171

1172-
def assert_pandas_batch_types(
1173-
batch: pandas.DataFrame, expected_types: list[type]
1174-
) -> None:
1175-
assert batch.dtypes is not None
1176-
1177-
pandas_dtypes = batch.dtypes
1178-
# pd.string is represented as an np.object
1179-
# np.dtype string is not the same as pd.string (python)
1180-
for pandas_dtype, expected_type in zip(pandas_dtypes, expected_types):
1181-
assert_dtype_equal(pandas_dtype.type, numpy.dtype(expected_type).type)
1182-
1183-
11841172
def test_pandas_dtypes(conn_cnx):
11851173
with conn_cnx(
11861174
session_parameters={
@@ -1191,12 +1179,18 @@ def test_pandas_dtypes(conn_cnx):
11911179
cur.execute(
11921180
"select 1::integer, 2.3::double, 'foo'::string, current_timestamp()::timestamp where 1=0"
11931181
)
1194-
expected_types = [numpy.int64, float, object, numpy.datetime64]
1195-
assert_pandas_batch_types(cur.fetch_pandas_all(), expected_types)
1196-
11971182
batches = cur.get_result_batches()
1183+
batch = batches[0].to_pandas()
1184+
1185+
assert batch.dtypes is not None
11981186
assert batches[0].to_arrow() is not True
1199-
assert_pandas_batch_types(batches[0].to_pandas(), expected_types)
1187+
1188+
pandas_dtypes = batch.dtypes
1189+
expected_types = [numpy.int64, float, object, numpy.datetime64]
1190+
# pd.string is represented as an np.object
1191+
# np.dtype string is not the same as pd.string (python)
1192+
for i, typ in enumerate(expected_types):
1193+
assert_dtype_equal(pandas_dtypes[i].type, numpy.dtype(typ).type)
12001194

12011195

12021196
def test_timestamp_tz(conn_cnx):

0 commit comments

Comments
 (0)