-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-1445838: Support DataFrame.items. (#2060)
Signed-off-by: sfc-gh-mvashishtha <[email protected]>
- Loading branch information
1 parent
9250c5a
commit 131e820
Showing
7 changed files
with
108 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# | ||
# Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved. | ||
# | ||
|
||
import pandas as native_pd | ||
import pytest | ||
|
||
from tests.integ.modin.sql_counter import SqlCounter | ||
from tests.integ.modin.utils import ( | ||
assert_snowpark_pandas_equals_to_pandas_without_dtypecheck, | ||
create_test_dfs, | ||
eval_snowpark_pandas_result, | ||
) | ||
|
||
|
||
def assert_items_results_equal(snow_result, pandas_result) -> None: | ||
snow_list = list(snow_result) | ||
pandas_list = list(pandas_result) | ||
assert len(snow_list) == len(pandas_list), "lengths of items are not equal." | ||
if len(snow_list) == 0: | ||
# Expect no queries if there are no columns. | ||
with SqlCounter(query_count=0): | ||
return | ||
for ((snow_label, snow_column), (pandas_label, pandas_column)) in zip( | ||
snow_list, pandas_list | ||
): | ||
assert snow_label == pandas_label | ||
# Execute one query to materialize each column. | ||
with SqlCounter(query_count=1): | ||
assert_snowpark_pandas_equals_to_pandas_without_dtypecheck( | ||
snow_column, pandas_column | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"dataframe", | ||
[ | ||
native_pd.DataFrame( | ||
{ | ||
"species": ["bear", "bear", "marsupial"], | ||
"population": [1864, 22000, 80000], | ||
}, | ||
index=["panda", "polar", "koala"], | ||
), | ||
native_pd.DataFrame( | ||
{ | ||
(0, "species"): ["bear", "bear", "marsupial"], | ||
(0, "population"): [1864, 22000, 80000], | ||
}, | ||
index=["panda", "polar", "koala"], | ||
), | ||
native_pd.DataFrame(index=["a"]), | ||
native_pd.DataFrame(columns=["a"]), | ||
], | ||
) | ||
def test_items(dataframe): | ||
eval_snowpark_pandas_result( | ||
*create_test_dfs(dataframe), | ||
lambda df: df.items(), | ||
comparator=assert_items_results_equal, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters