Skip to content

Commit 8237a86

Browse files
SNOW-2430578: Add support for invert in faster pandas (#3895)
1 parent ca7b120 commit 8237a86

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
@@ -112,6 +112,7 @@
112112
- `loc` (setting columns)
113113
- `to_datetime`
114114
- `drop`
115+
- `invert`
115116
- Reuse row count from the relaxed query compiler in `get_axis_len`.
116117

117118
#### Bug Fixes

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11434,6 +11434,16 @@ def transpose(self) -> "SnowflakeQueryCompiler":
1143411434
return SnowflakeQueryCompiler(new_internal_frame)
1143511435

1143611436
def invert(self) -> "SnowflakeQueryCompiler":
11437+
"""
11438+
Wrapper around _invert_internal to be supported in faster pandas.
11439+
"""
11440+
relaxed_query_compiler = None
11441+
if self._relaxed_query_compiler is not None:
11442+
relaxed_query_compiler = self._relaxed_query_compiler._invert_internal()
11443+
qc = self._invert_internal()
11444+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
11445+
11446+
def _invert_internal(self) -> "SnowflakeQueryCompiler":
1143711447
"""
1143811448
Apply bitwise inversion for each element of the QueryCompiler.
1143911449

tests/integ/modin/test_faster_pandas.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,35 @@ def test_drop(session):
223223
assert_frame_equal(snow_result, native_result)
224224

225225

226+
@sql_count_checker(query_count=3)
227+
def test_invert(session):
228+
# create tables
229+
table_name = Utils.random_name_for_temp_object(TempObjectType.TABLE)
230+
session.create_dataframe(
231+
native_pd.DataFrame([[2, True], [1, False], [3, False]], columns=["A", "B"])
232+
).write.save_as_table(table_name, table_type="temp")
233+
234+
# create snow dataframes
235+
df = pd.read_snowflake(table_name)
236+
snow_result = ~df["B"]
237+
238+
# verify that the input dataframe has a populated relaxed query compiler
239+
assert df._query_compiler._relaxed_query_compiler is not None
240+
assert df._query_compiler._relaxed_query_compiler._dummy_row_pos_mode is True
241+
# verify that the output dataframe also has a populated relaxed query compiler
242+
assert snow_result._query_compiler._relaxed_query_compiler is not None
243+
assert (
244+
snow_result._query_compiler._relaxed_query_compiler._dummy_row_pos_mode is True
245+
)
246+
247+
# create pandas dataframes
248+
native_df = df.to_pandas()
249+
native_result = ~native_df["B"]
250+
251+
# compare results
252+
assert_series_equal(snow_result, native_result)
253+
254+
226255
@pytest.mark.parametrize("func", ["isna", "isnull", "notna", "notnull"])
227256
@sql_count_checker(query_count=3)
228257
def test_isna_notna(session, func):

0 commit comments

Comments
 (0)