-
Notifications
You must be signed in to change notification settings - Fork 143
SNOW-2435290: Add support for groupby.agg/min/max/count/sum/mean/median/std/var in faster pandas #3908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
SNOW-2435290: Add support for groupby.agg/min/max/count/sum/mean/median/std/var in faster pandas #3908
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b44816c
SNOW-2435290: Add support for groupby.agg/min/max/count/sum/mean/medi…
sfc-gh-helmeleegy ef3cda2
fix errors
sfc-gh-helmeleegy 8c7e94a
Merge branch 'main' into helmeleegy-SNOW-2435290
sfc-gh-helmeleegy f9a6075
address comments
sfc-gh-helmeleegy 81309c5
Merge branch 'main' into helmeleegy-SNOW-2435290
sfc-gh-helmeleegy b64330f
Merge branch 'main' into helmeleegy-SNOW-2435290
sfc-gh-helmeleegy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -124,9 +124,9 @@ def test_read_filter_join_on_index(session): | |
| ) | ||
|
|
||
|
|
||
| @sql_count_checker(query_count=3) | ||
| def test_read_filter_groupby_agg(session): | ||
| # test a chain of operations that are not fully supported in faster pandas | ||
| @sql_count_checker(query_count=3, join_count=2) | ||
| def test_read_filter_iloc_index(session): | ||
| # test a chain of operations that are not yet fully supported in faster pandas | ||
|
|
||
| # create tables | ||
| table_name = Utils.random_name_for_temp_object(TempObjectType.TABLE) | ||
|
|
@@ -136,19 +136,19 @@ def test_read_filter_groupby_agg(session): | |
|
|
||
| # create snow dataframes | ||
| df = pd.read_snowflake(table_name) | ||
| snow_result = df[df["B"] > 11].groupby("A").min() | ||
| snow_result = df.iloc[[1], :] | ||
|
|
||
| # verify that the input dataframe has a populated relaxed query compiler | ||
| assert df._query_compiler._relaxed_query_compiler is not None | ||
| assert df._query_compiler._relaxed_query_compiler._dummy_row_pos_mode is True | ||
| # verify that the output dataframe has an empty relaxed query compiler | ||
| # because groupby() and min() are not supported in faster pandas yet | ||
| # because iloc for index is not supported in faster pandas yet | ||
| assert snow_result._query_compiler._relaxed_query_compiler is None | ||
| assert snow_result._query_compiler._dummy_row_pos_mode is False | ||
|
|
||
| # create pandas dataframes | ||
| native_df = df.to_pandas() | ||
| native_result = native_df[native_df["B"] > 11].groupby("A").min() | ||
| native_result = native_df.iloc[[1], :] | ||
|
|
||
| # compare results | ||
| assert_frame_equal(snow_result, native_result) | ||
|
|
@@ -308,6 +308,61 @@ def test_duplicated(session): | |
| assert_series_equal(snow_result, native_result) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "func", | ||
| [ | ||
| "min", | ||
| "max", | ||
| "count", | ||
| "sum", | ||
| "mean", | ||
| "median", | ||
| "std", | ||
| "var", | ||
| ], | ||
| ) | ||
| @sql_count_checker(query_count=6) | ||
| def test_groupby_agg(session, func): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like a lot of the fasters pandas tests have some pretty similar setup/assert/teardown code. Could you add some of that logic to a shared logic/fixture in the future? |
||
| # create tables | ||
| table_name = Utils.random_name_for_temp_object(TempObjectType.TABLE) | ||
| session.create_dataframe( | ||
| native_pd.DataFrame([[2, 12], [2, 11], [3, 13]], columns=["A", "B"]) | ||
| ).write.save_as_table(table_name, table_type="temp") | ||
|
|
||
| # create snow dataframes | ||
| df = pd.read_snowflake(table_name) | ||
| snow_result1 = getattr(df.groupby("A"), func)() | ||
| snow_result2 = df.groupby("A").agg([func]) | ||
| snow_result3 = getattr(df.groupby("A")["B"], func)() | ||
| snow_result4 = df.groupby("A")["B"].agg([func]) | ||
|
|
||
| # verify that the input dataframe has a populated relaxed query compiler | ||
| assert df._query_compiler._relaxed_query_compiler is not None | ||
| assert df._query_compiler._relaxed_query_compiler._dummy_row_pos_mode is True | ||
| # verify that the output dataframe also has a populated relaxed query compiler | ||
| assert snow_result1._query_compiler._relaxed_query_compiler is not None | ||
| assert ( | ||
| snow_result1._query_compiler._relaxed_query_compiler._dummy_row_pos_mode is True | ||
| ) | ||
| assert snow_result2._query_compiler._relaxed_query_compiler is not None | ||
| assert ( | ||
| snow_result2._query_compiler._relaxed_query_compiler._dummy_row_pos_mode is True | ||
| ) | ||
|
|
||
| # create pandas dataframes | ||
| native_df = df.to_pandas() | ||
| native_result1 = getattr(native_df.groupby("A"), func)() | ||
| native_result2 = native_df.groupby("A").agg([func]) | ||
| native_result3 = getattr(native_df.groupby("A")["B"], func)() | ||
| native_result4 = native_df.groupby("A")["B"].agg([func]) | ||
|
|
||
| # compare results | ||
| assert_frame_equal(snow_result1, native_result1, check_dtype=False) | ||
| assert_frame_equal(snow_result2, native_result2, check_dtype=False) | ||
| assert_series_equal(snow_result3, native_result3, check_dtype=False) | ||
| assert_frame_equal(snow_result4, native_result4, check_dtype=False) | ||
|
|
||
|
|
||
| @sql_count_checker(query_count=5) | ||
| def test_iloc_head(session): | ||
| # create tables | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.