Skip to content

Commit 4ffe411

Browse files
SNOW-2458028: Add support for copy in faster pandas (#3956)
1 parent a4902f2 commit 4ffe411

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- `groupby.nunique`
3636
- `groupby.size`
3737
- `concat`
38+
- `copy`
3839

3940
## 1.41.0 (2025-10-23)
4041

src/snowflake/snowpark/modin/plugin/compiler/snowflake_query_compiler.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,16 @@ def from_date_range(
14821482

14831483
@snowpark_pandas_type_immutable_check
14841484
def copy(self) -> "SnowflakeQueryCompiler":
1485+
"""
1486+
Wrapper around _copy_internal to be supported in faster pandas.
1487+
"""
1488+
relaxed_query_compiler = None
1489+
if self._relaxed_query_compiler is not None:
1490+
relaxed_query_compiler = self._relaxed_query_compiler._copy_internal()
1491+
qc = self._copy_internal()
1492+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
1493+
1494+
def _copy_internal(self) -> "SnowflakeQueryCompiler":
14851495
"""
14861496
Make a copy of this object.
14871497

tests/integ/modin/test_faster_pandas.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,35 @@ def test_concat(session):
287287
assert_frame_equal(snow_result, native_result)
288288

289289

290+
@sql_count_checker(query_count=3)
291+
def test_copy(session):
292+
# create tables
293+
table_name = Utils.random_name_for_temp_object(TempObjectType.TABLE)
294+
session.create_dataframe(
295+
native_pd.DataFrame([[2, True], [1, False], [3, False]], columns=["A", "B"])
296+
).write.save_as_table(table_name, table_type="temp")
297+
298+
# create snow dataframes
299+
df = pd.read_snowflake(table_name)
300+
snow_result = df.copy()
301+
302+
# verify that the input dataframe has a populated relaxed query compiler
303+
assert df._query_compiler._relaxed_query_compiler is not None
304+
assert df._query_compiler._relaxed_query_compiler._dummy_row_pos_mode is True
305+
# verify that the output dataframe also has a populated relaxed query compiler
306+
assert snow_result._query_compiler._relaxed_query_compiler is not None
307+
assert (
308+
snow_result._query_compiler._relaxed_query_compiler._dummy_row_pos_mode is True
309+
)
310+
311+
# create pandas dataframes
312+
native_df = df.to_pandas()
313+
native_result = native_df.copy()
314+
315+
# compare results
316+
assert_frame_equal(snow_result, native_result)
317+
318+
290319
@sql_count_checker(query_count=3)
291320
def test_drop(session):
292321
# create tables

0 commit comments

Comments
 (0)