-
Notifications
You must be signed in to change notification settings - Fork 144
SNOW-1893939: Add support for Index.drop_duplicates #2923
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
sfc-gh-amaheshwary
merged 8 commits into
main
from
amaheshwary-SNOW-1893939-indexDropDuplicates
Jan 27, 2025
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bc4c3d5
Add support for Index.drop_duplicates
sfc-gh-amaheshwary 7c48695
Add more tests for Index.drop_duplicates
sfc-gh-amaheshwary e01fc50
Reimplmement Index.drop_duplicates to avoid materialization
sfc-gh-amaheshwary b6b1ac5
Add style fixes and input validation for Series.drop_duplicates
sfc-gh-amaheshwary 8afbd3d
Remove references to drop_duplicates in unimplemented tests
sfc-gh-amaheshwary 5488bfc
Merge branch 'main' into amaheshwary-SNOW-1893939-indexDropDuplicates
sfc-gh-amaheshwary 55d334e
Merge branch 'main' into amaheshwary-SNOW-1893939-indexDropDuplicates
sfc-gh-amaheshwary 928ee4f
Add test for invalid keep parameter in Series.drop_duplicates
sfc-gh-amaheshwary 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
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 |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # | ||
| # Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved. | ||
| # | ||
|
|
||
| import modin.pandas as pd | ||
| import numpy as np | ||
| import pandas as native_pd | ||
| import pytest | ||
|
|
||
| import snowflake.snowpark.modin.plugin # noqa: F401 | ||
| from tests.integ.modin.utils import assert_index_equal | ||
| from tests.integ.utils.sql_counter import sql_count_checker | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("keep", ["first", "last", False]) | ||
| @sql_count_checker(query_count=1, join_count=2) | ||
| def test_drop_duplicates(keep): | ||
| pandas_idx = native_pd.Index(["a", "b", "b", "c", "a"], name="name") | ||
| snow_idx = pd.Index(pandas_idx) | ||
|
|
||
| assert_index_equal( | ||
| snow_idx.drop_duplicates(keep=keep), | ||
| pandas_idx.drop_duplicates(keep=keep), | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("keep", ["first", "last", False]) | ||
| @sql_count_checker(query_count=1, join_count=2) | ||
| def test_drop_duplicates_on_empty_index(keep): | ||
| pandas_idx = native_pd.Index([], name="name") | ||
| snow_idx = pd.Index(pandas_idx) | ||
|
|
||
| assert_index_equal( | ||
| snow_idx.drop_duplicates(keep=keep), | ||
| pandas_idx.drop_duplicates(keep=keep), | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "keep, expected", | ||
| [ | ||
| ("first", native_pd.Index([np.nan, 3])), | ||
| ("last", native_pd.Index([3, np.nan])), | ||
| (False, native_pd.Index([], dtype="float64")), | ||
| ], | ||
| ) | ||
| @sql_count_checker(query_count=1, join_count=2) | ||
sfc-gh-jkew marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_drop_duplicates_nan_none(keep, expected): | ||
| # Note that Snowpark pandas treats np.nan and None the same | ||
| idx = pd.Index([np.nan, 3, 3, None, np.nan], dtype=object) | ||
|
|
||
| result = idx.drop_duplicates(keep=keep) | ||
| assert_index_equal( | ||
| result, | ||
| expected, | ||
| ) | ||
sfc-gh-nkrishna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
sfc-gh-nkrishna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @sql_count_checker(query_count=1, join_count=2) | ||
| def test_drop_duplicates_default_keep(): | ||
| pandas_idx = native_pd.Index([], name="name") | ||
| snow_idx = pd.Index(pandas_idx) | ||
|
|
||
| assert_index_equal( | ||
| snow_idx.drop_duplicates(), | ||
| pandas_idx.drop_duplicates(), | ||
| ) | ||
|
|
||
|
|
||
| @sql_count_checker(query_count=0, join_count=0) | ||
| def test_drop_duplicates_invalid_keep(): | ||
| snow_idx = pd.Index(["a", "b", "b", "c", "a"], name="name") | ||
| with pytest.raises( | ||
| ValueError, match='keep must be either "first", "last" or False' | ||
| ): | ||
| snow_idx.drop_duplicates(keep="invalid") | ||
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.