You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/03/29 18:06:09 UTC
[GitHub] [spark] xinrong-databricks opened a new pull request #36006: Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
xinrong-databricks opened a new pull request #36006:
URL: https://github.com/apache/spark/pull/36006
### What changes were proposed in this pull request?
Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates` to specify how to handle dropping duplicates.
### Why are the changes needed?
To reach parity with pandas.
### Does this PR introduce _any_ user-facing change?
Yes, `keep` parameter of `(Index/MultiIndex).drop_duplicates` is supported now.
Take MultiIndex for example,
```py
>>> arrays = [[1, 2, 3, 1, 2], ["red", "blue", "black", "red", "blue"]]
>>> midx = ps.MultiIndex.from_arrays(arrays, names=("number", "color"))
>>> midx
MultiIndex([(1, 'red'),
(2, 'blue'),
(3, 'black'),
(1, 'red'),
(2, 'blue')],
names=['number', 'color'])
>>> midx.drop_duplicates()
MultiIndex([(1, 'red'),
(2, 'blue'),
(3, 'black')],
names=['number', 'color'])
>>> midx.drop_duplicates(keep='first')
MultiIndex([(1, 'red'),
(2, 'blue'),
(3, 'black')],
names=['number', 'color'])
>>> midx.drop_duplicates(keep='last')
MultiIndex([(3, 'black'),
(1, 'red'),
(2, 'blue')],
names=['number', 'color'])
>>> midx.drop_duplicates(keep=False)
MultiIndex([(3, 'black')],
names=['number', 'color'])
```
### How was this patch tested?
Unit tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xinrong-databricks commented on pull request #36006: [SPARK-38686][PYTHON] Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
xinrong-databricks commented on pull request #36006:
URL: https://github.com/apache/spark/pull/36006#issuecomment-1082365795
Thanks @bjornjorgensen !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xinrong-databricks commented on pull request #36006: [SPARK-38686][PYTHON] Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
xinrong-databricks commented on pull request #36006:
URL: https://github.com/apache/spark/pull/36006#issuecomment-1082366069
CC @ueshin @HyukjinKwon @itholic Thank you!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xinrong-databricks commented on a change in pull request #36006: [SPARK-38686][PYTHON] Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
xinrong-databricks commented on a change in pull request #36006:
URL: https://github.com/apache/spark/pull/36006#discussion_r839858561
##########
File path: python/pyspark/pandas/indexes/base.py
##########
@@ -898,25 +905,19 @@ def drop_duplicates(self) -> "Index":
Examples
--------
- Generate an pandas.Index with duplicate values.
+ Generate an Index with duplicate values.
>>> idx = ps.Index(['lama', 'cow', 'lama', 'beetle', 'lama', 'hippo'])
>>> idx.drop_duplicates().sort_values()
Index(['beetle', 'cow', 'hippo', 'lama'], dtype='object')
"""
- sdf = self._internal.spark_frame.select(
- self._internal.index_spark_columns
- ).drop_duplicates()
- internal = InternalFrame(
- spark_frame=sdf,
- index_spark_columns=[
- scol_for(sdf, col) for col in self._internal.index_spark_column_names
- ],
- index_names=self._internal.index_names,
- index_fields=self._internal.index_fields,
- )
- return DataFrame(internal).index
+ with ps.option_context("compute.default_index_type", "distributed"):
+ # The attached index caused by `reset_index` below is used for sorting only,
+ # and it will be dropped soon,
+ # so we enforce “distributed” default index type
+ psser = self.to_series().reset_index(drop=True)
+ return Index(psser.drop_duplicates(keep=keep).sort_index())
Review comment:
Agree, thank you @itholic !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon closed pull request #36006: [SPARK-38686][PYTHON] Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
HyukjinKwon closed pull request #36006:
URL: https://github.com/apache/spark/pull/36006
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] bjornjorgensen commented on pull request #36006: Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
bjornjorgensen commented on pull request #36006:
URL: https://github.com/apache/spark/pull/36006#issuecomment-1082233674
Generate a Index with duplicate values. -> Generate an Index with duplicate values.
:)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xinrong-databricks commented on a change in pull request #36006: [SPARK-38686][PYTHON] Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
xinrong-databricks commented on a change in pull request #36006:
URL: https://github.com/apache/spark/pull/36006#discussion_r841262157
##########
File path: python/pyspark/pandas/indexes/multi.py
##########
@@ -893,6 +893,70 @@ def drop(self, codes: List[Any], level: Optional[Union[int, Name]] = None) -> "M
)
return cast(MultiIndex, DataFrame(internal).index)
+ def drop_duplicates(self, keep: Union[bool, str] = "first") -> "MultiIndex":
+ """
Review comment:
Thank!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xinrong-databricks commented on a change in pull request #36006: [SPARK-38686][PYTHON] Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
xinrong-databricks commented on a change in pull request #36006:
URL: https://github.com/apache/spark/pull/36006#discussion_r839000623
##########
File path: python/pyspark/pandas/indexes/base.py
##########
@@ -898,25 +905,19 @@ def drop_duplicates(self) -> "Index":
Examples
--------
- Generate an pandas.Index with duplicate values.
+ Generate an Index with duplicate values.
>>> idx = ps.Index(['lama', 'cow', 'lama', 'beetle', 'lama', 'hippo'])
>>> idx.drop_duplicates().sort_values()
Index(['beetle', 'cow', 'hippo', 'lama'], dtype='object')
"""
- sdf = self._internal.spark_frame.select(
- self._internal.index_spark_columns
- ).drop_duplicates()
- internal = InternalFrame(
- spark_frame=sdf,
- index_spark_columns=[
- scol_for(sdf, col) for col in self._internal.index_spark_column_names
- ],
- index_names=self._internal.index_names,
- index_fields=self._internal.index_fields,
- )
- return DataFrame(internal).index
+ with ps.option_context("compute.default_index_type", "distributed"):
+ # The attached index caused by `reset_index` below is used for sorting only,
+ # and it will be dropped soon,
+ # so we enforce “distributed” default index type
+ psser = self.to_series().reset_index(drop=True)
+ return Index(psser.drop_duplicates(keep=keep).sort_index())
Review comment:
Due to the Spark optimizer, only two Spark jobs are created finally. If that's acceptable I would prefer the code clarity. What do you think about that?
<img width="683" alt="image" src="https://user-images.githubusercontent.com/47337188/160937776-a8cde469-e58a-402f-aa65-5558a993c3ee.png">
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xinrong-databricks commented on a change in pull request #36006: [SPARK-38686][PYTHON] Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
xinrong-databricks commented on a change in pull request #36006:
URL: https://github.com/apache/spark/pull/36006#discussion_r840681722
##########
File path: python/pyspark/pandas/indexes/multi.py
##########
@@ -893,6 +893,70 @@ def drop(self, codes: List[Any], level: Optional[Union[int, Name]] = None) -> "M
)
return cast(MultiIndex, DataFrame(internal).index)
+ def drop_duplicates(self, keep: Union[bool, str] = "first") -> "MultiIndex":
+ """
Review comment:
`MultiIndex.drop_duplicates` was supported before 3.4, here we separate the code path in order to better support the `keep` parameter.
Shall we add `versionadded:: 3.4.0` to the parameter?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] itholic commented on a change in pull request #36006: [SPARK-38686][PYTHON] Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
itholic commented on a change in pull request #36006:
URL: https://github.com/apache/spark/pull/36006#discussion_r839009017
##########
File path: python/pyspark/pandas/indexes/base.py
##########
@@ -898,25 +905,19 @@ def drop_duplicates(self) -> "Index":
Examples
--------
- Generate an pandas.Index with duplicate values.
+ Generate an Index with duplicate values.
>>> idx = ps.Index(['lama', 'cow', 'lama', 'beetle', 'lama', 'hippo'])
>>> idx.drop_duplicates().sort_values()
Index(['beetle', 'cow', 'hippo', 'lama'], dtype='object')
"""
- sdf = self._internal.spark_frame.select(
- self._internal.index_spark_columns
- ).drop_duplicates()
- internal = InternalFrame(
- spark_frame=sdf,
- index_spark_columns=[
- scol_for(sdf, col) for col in self._internal.index_spark_column_names
- ],
- index_names=self._internal.index_names,
- index_fields=self._internal.index_fields,
- )
- return DataFrame(internal).index
+ with ps.option_context("compute.default_index_type", "distributed"):
+ # The attached index caused by `reset_index` below is used for sorting only,
+ # and it will be dropped soon,
+ # so we enforce “distributed” default index type
+ psser = self.to_series().reset_index(drop=True)
+ return Index(psser.drop_duplicates(keep=keep).sort_index())
Review comment:
Yes, it is true that only 2 jobs are executed, but I am concerned that `sort_index` is a fairly expensive operation.
But as long as there's no way to avoid `sort_index` or replace it with a cheaper operation, it looks fine as is.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] itholic commented on a change in pull request #36006: [SPARK-38686][PYTHON] Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
itholic commented on a change in pull request #36006:
URL: https://github.com/apache/spark/pull/36006#discussion_r839009017
##########
File path: python/pyspark/pandas/indexes/base.py
##########
@@ -898,25 +905,19 @@ def drop_duplicates(self) -> "Index":
Examples
--------
- Generate an pandas.Index with duplicate values.
+ Generate an Index with duplicate values.
>>> idx = ps.Index(['lama', 'cow', 'lama', 'beetle', 'lama', 'hippo'])
>>> idx.drop_duplicates().sort_values()
Index(['beetle', 'cow', 'hippo', 'lama'], dtype='object')
"""
- sdf = self._internal.spark_frame.select(
- self._internal.index_spark_columns
- ).drop_duplicates()
- internal = InternalFrame(
- spark_frame=sdf,
- index_spark_columns=[
- scol_for(sdf, col) for col in self._internal.index_spark_column_names
- ],
- index_names=self._internal.index_names,
- index_fields=self._internal.index_fields,
- )
- return DataFrame(internal).index
+ with ps.option_context("compute.default_index_type", "distributed"):
+ # The attached index caused by `reset_index` below is used for sorting only,
+ # and it will be dropped soon,
+ # so we enforce “distributed” default index type
+ psser = self.to_series().reset_index(drop=True)
+ return Index(psser.drop_duplicates(keep=keep).sort_index())
Review comment:
Yes, it is true that only 2 jobs are executed, but I am concerned that `sort_index` is a fairly expensive operation.
But as long as there's no way to avoid `sort_index` or replace it with a cheaper operation for now, it looks fine as is.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on a change in pull request #36006: [SPARK-38686][PYTHON] Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #36006:
URL: https://github.com/apache/spark/pull/36006#discussion_r841135912
##########
File path: python/pyspark/pandas/indexes/multi.py
##########
@@ -893,6 +893,70 @@ def drop(self, codes: List[Any], level: Optional[Union[int, Name]] = None) -> "M
)
return cast(MultiIndex, DataFrame(internal).index)
+ def drop_duplicates(self, keep: Union[bool, str] = "first") -> "MultiIndex":
+ """
Review comment:
Technically we should add `versionchanged: 3.4.0` for the argument.. but i guess it's fine for now,
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on pull request #36006: [SPARK-38686][PYTHON] Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #36006:
URL: https://github.com/apache/spark/pull/36006#issuecomment-1086751098
Merged to master.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on a change in pull request #36006: [SPARK-38686][PYTHON] Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #36006:
URL: https://github.com/apache/spark/pull/36006#discussion_r840222014
##########
File path: python/pyspark/pandas/indexes/multi.py
##########
@@ -893,6 +893,70 @@ def drop(self, codes: List[Any], level: Optional[Union[int, Name]] = None) -> "M
)
return cast(MultiIndex, DataFrame(internal).index)
+ def drop_duplicates(self, keep: Union[bool, str] = "first") -> "MultiIndex":
+ """
Review comment:
Let's add `versionadded: 3.4.0` in the docstring.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] itholic commented on a change in pull request #36006: [SPARK-38686][PYTHON] Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
itholic commented on a change in pull request #36006:
URL: https://github.com/apache/spark/pull/36006#discussion_r837986152
##########
File path: python/pyspark/pandas/tests/indexes/test_base.py
##########
@@ -368,10 +368,19 @@ def test_drop_duplicates(self):
pidx = pd.Index([4, 2, 4, 1, 4, 3])
psidx = ps.from_pandas(pidx)
- self.assert_eq(psidx.drop_duplicates().sort_values(), pidx.drop_duplicates().sort_values())
- self.assert_eq(
- (psidx + 1).drop_duplicates().sort_values(), (pidx + 1).drop_duplicates().sort_values()
- )
+ self.assert_eq(psidx.drop_duplicates(), pidx.drop_duplicates())
+ self.assert_eq((psidx + 1).drop_duplicates(), (pidx + 1).drop_duplicates())
+
+ self.assert_eq(psidx.drop_duplicates(keep="first"), pidx.drop_duplicates(keep="first"))
+ self.assert_eq(psidx.drop_duplicates(keep="last"), pidx.drop_duplicates(keep="last"))
+ self.assert_eq(psidx.drop_duplicates(keep=False), pidx.drop_duplicates(keep=False))
+
+ arrays = [[1, 2, 3, 1, 2], ["red", "blue", "black", "red", "blue"]]
+ pmidx = pd.MultiIndex.from_arrays(arrays, names=("number", "color"))
+ psmidx = ps.from_pandas(pmidx)
+ self.assert_eq(psmidx.drop_duplicates(keep="first"), pmidx.drop_duplicates(keep="first"))
+ self.assert_eq(psmidx.drop_duplicates(keep="last"), pmidx.drop_duplicates(keep="last"))
+ self.assert_eq(psmidx.drop_duplicates(keep=False), pmidx.drop_duplicates(keep=False))
Review comment:
Shall we also have a test for the default case for `MultiIndex`?
```python
self.assert_eq(psmidx.drop_duplicates(), pmidx.drop_duplicates())
```
##########
File path: python/pyspark/pandas/indexes/base.py
##########
@@ -898,25 +905,19 @@ def drop_duplicates(self) -> "Index":
Examples
--------
- Generate an pandas.Index with duplicate values.
+ Generate an Index with duplicate values.
>>> idx = ps.Index(['lama', 'cow', 'lama', 'beetle', 'lama', 'hippo'])
>>> idx.drop_duplicates().sort_values()
Index(['beetle', 'cow', 'hippo', 'lama'], dtype='object')
"""
- sdf = self._internal.spark_frame.select(
- self._internal.index_spark_columns
- ).drop_duplicates()
- internal = InternalFrame(
- spark_frame=sdf,
- index_spark_columns=[
- scol_for(sdf, col) for col in self._internal.index_spark_column_names
- ],
- index_names=self._internal.index_names,
- index_fields=self._internal.index_fields,
- )
- return DataFrame(internal).index
+ with ps.option_context("compute.default_index_type", "distributed"):
+ # The attached index caused by `reset_index` below is used for sorting only,
+ # and it will be dropped soon,
+ # so we enforce “distributed” default index type
+ psser = self.to_series().reset_index(drop=True)
+ return Index(psser.drop_duplicates(keep=keep).sort_index())
Review comment:
I think maybe we should manually manage the `keep` parameter in single pass like we're doing for `DataFrame.drop_duplicates` as below if possible ?
https://github.com/apache/spark/blob/master/python/pyspark/pandas/frame.py#L4330-L4347
https://github.com/apache/spark/blob/42a9114f4c509f1f369bfb1499ea99c187518c48/python/pyspark/pandas/frame.py#L4330-L4347
I just concern that seems like the APIs such as `to_series()`, `reset_index()`, `drop_duplicates()` and `sort_index()` may trigger the multiple Spark job which is potentially very expensive.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xinrong-databricks commented on a change in pull request #36006: [SPARK-38686][PYTHON] Implement `keep` parameter of `(Index/MultiIndex).drop_duplicates`
Posted by GitBox <gi...@apache.org>.
xinrong-databricks commented on a change in pull request #36006:
URL: https://github.com/apache/spark/pull/36006#discussion_r838798914
##########
File path: python/pyspark/pandas/tests/indexes/test_base.py
##########
@@ -368,10 +368,19 @@ def test_drop_duplicates(self):
pidx = pd.Index([4, 2, 4, 1, 4, 3])
psidx = ps.from_pandas(pidx)
- self.assert_eq(psidx.drop_duplicates().sort_values(), pidx.drop_duplicates().sort_values())
- self.assert_eq(
- (psidx + 1).drop_duplicates().sort_values(), (pidx + 1).drop_duplicates().sort_values()
- )
+ self.assert_eq(psidx.drop_duplicates(), pidx.drop_duplicates())
+ self.assert_eq((psidx + 1).drop_duplicates(), (pidx + 1).drop_duplicates())
+
+ self.assert_eq(psidx.drop_duplicates(keep="first"), pidx.drop_duplicates(keep="first"))
+ self.assert_eq(psidx.drop_duplicates(keep="last"), pidx.drop_duplicates(keep="last"))
+ self.assert_eq(psidx.drop_duplicates(keep=False), pidx.drop_duplicates(keep=False))
+
+ arrays = [[1, 2, 3, 1, 2], ["red", "blue", "black", "red", "blue"]]
+ pmidx = pd.MultiIndex.from_arrays(arrays, names=("number", "color"))
+ psmidx = ps.from_pandas(pmidx)
+ self.assert_eq(psmidx.drop_duplicates(keep="first"), pmidx.drop_duplicates(keep="first"))
+ self.assert_eq(psmidx.drop_duplicates(keep="last"), pmidx.drop_duplicates(keep="last"))
+ self.assert_eq(psmidx.drop_duplicates(keep=False), pmidx.drop_duplicates(keep=False))
Review comment:
Added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org