Skip to content

Commit 15f9e44

Browse files
SNOW-2217588:add support for USE_VECTORIZED_SCANNER in write_pandas() (#3759)
1 parent 4750a63 commit 15f9e44

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Added a new function `interval_year_month_from_parts` that allows users to easily create `YearMonthIntervalType` without using SQL.
1111
- Added support for `FileOperation.list` to list files in a stage with metadata.
1212
- Added support for `FileOperation.remove` to remove files in a stage.
13+
- Added support for parameter `use_vectorized_scanner` in function `Session.write_pandas()`.
1314

1415
#### Bug Fixes
1516

src/snowflake/snowpark/session.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,6 +3190,7 @@ def write_pandas(
31903190
overwrite: bool = False,
31913191
table_type: Literal["", "temp", "temporary", "transient"] = "",
31923192
use_logical_type: Optional[bool] = None,
3193+
use_vectorized_scanner: bool = False,
31933194
_emit_ast: bool = True,
31943195
**kwargs: Dict[str, Any],
31953196
) -> Table:
@@ -3235,6 +3236,8 @@ def write_pandas(
32353236
types during data loading. To enable Parquet logical types, set use_logical_type as True. Set to None to
32363237
use Snowflakes default. For more information, see:
32373238
`file format options: <https://docs.snowflake.com/en/sql-reference/sql/create-file-format#type-parquet>`_.
3239+
use_vectorized_scanner: Boolean that specifies whether to use a vectorized scanner for loading Parquet files. See details at
3240+
`copy options <https://docs.snowflake.com/en/sql-reference/sql/copy-into-table.html#copy-options-copyoptions>`_.
32383241
32393242
Example::
32403243
@@ -3374,6 +3377,7 @@ def write_pandas(
33743377
auto_create_table=auto_create_table,
33753378
overwrite=overwrite,
33763379
table_type=table_type,
3380+
use_vectorized_scanner=use_vectorized_scanner,
33773381
**kwargs,
33783382
)
33793383
except ProgrammingError as pe:

tests/integ/test_pandas_to_df.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import logging
99
import math
1010
from datetime import date, datetime, time, timedelta, timezone
11+
from unittest import mock
1112

1213
import pytest
1314

@@ -325,6 +326,41 @@ def test_write_pandas_with_table_type(session, table_type: str):
325326
Utils.drop_table(session, table_name)
326327

327328

329+
@pytest.mark.skipif(
330+
"config.getoption('local_testing_mode', default=False)",
331+
reason="SNOW-1421323: session.write_pandas is not supported in Local Testing.",
332+
)
333+
@pytest.mark.parametrize("use_vectorized_scanner", [False, True])
334+
def test_write_pandas_use_vectorized_scanner(session, use_vectorized_scanner):
335+
from snowflake.connector.pandas_tools import write_pandas
336+
337+
original_func = write_pandas
338+
339+
def wrapper(*args, **kwargs):
340+
return original_func(*args, **kwargs)
341+
342+
pd = PandasDF(
343+
[
344+
(1, 4.5, "t1"),
345+
(2, 7.5, "t2"),
346+
(3, 10.5, "t3"),
347+
],
348+
columns=["id".upper(), "foot_size".upper(), "shoe_model".upper()],
349+
)
350+
tb_name = Utils.random_name_for_temp_object(TempObjectType.TABLE)
351+
with mock.patch(
352+
"snowflake.snowpark.session.write_pandas", side_effect=wrapper
353+
) as execute:
354+
session.write_pandas(
355+
pd,
356+
tb_name,
357+
auto_create_table=True,
358+
use_vectorized_scanner=use_vectorized_scanner,
359+
)
360+
_, kwargs = execute.call_args
361+
assert kwargs["use_vectorized_scanner"] == use_vectorized_scanner
362+
363+
328364
@pytest.mark.skipif(
329365
"config.getoption('local_testing_mode', default=False)",
330366
reason="SNOW-1421323: session.write_pandas is not supported in Local Testing.",

0 commit comments

Comments
 (0)