allisonwang-db commented on code in PR #47835:
URL: https://github.com/apache/spark/pull/47835#discussion_r1726070936
##########
python/pyspark/sql/classic/dataframe.py:
##########
@@ -1222,46 +1222,76 @@ def intersectAll(self, other: ParentDataFrame) ->
ParentDataFrame:
def subtract(self, other: ParentDataFrame) -> ParentDataFrame:
return DataFrame(getattr(self._jdf, "except")(other._jdf),
self.sparkSession)
- def dropDuplicates(self, *subset: Union[str, List[str]]) ->
ParentDataFrame:
- # Acceptable args should be str, ... or a single List[str]
- # So if subset length is 1, it can be either single str, or a list of
str
- # if subset length is greater than 1, it must be a sequence of str
- if not subset:
+ def dropDuplicates(
+ self, subset: Optional[Union[str, List[str], _NoValueType]] =
_NoValue, *subset_varargs: str
+ ) -> ParentDataFrame:
+ # No parameter passed in (e.g. dropDuplicates())
+ if subset is _NoValue:
jdf = self._jdf.dropDuplicates()
- elif len(subset) == 1 and isinstance(subset[0], list):
- item = subset[0]
+ # Parameters passed in as varargs
+ # (e.g. dropDuplicates("col"), dropDuplicates("col1", "col2"), ...)
+ elif isinstance(subset, str):
+ item = [subset] + list(subset_varargs)
Review Comment:
Can we also add some tests where it (subset and subset_varargs) has invalid
values?
##########
python/pyspark/sql/dataframe.py:
##########
@@ -4570,7 +4570,9 @@ def subtract(self, other: "DataFrame") -> "DataFrame":
...
@dispatch_df_method
- def dropDuplicates(self, *subset: Union[str, List[str]]) -> "DataFrame":
+ def dropDuplicates(
+ self, subset: Optional[Union[str, List[str], _NoValueType]] =
_NoValue, *subset_varargs: str
+ ) -> "DataFrame":
Review Comment:
Can we also update the docstring here for `subset` and add `subset_varargs`?
Also add more examples?
##########
python/pyspark/sql/tests/connect/test_connect_basic.py:
##########
@@ -663,25 +663,68 @@ def test_sql_with_invalid_args(self):
def test_deduplicate(self):
# SPARK-41326: test distinct and dropDuplicates.
- df = self.connect.read.table(self.tbl_name)
- df2 = self.spark.read.table(self.tbl_name)
+ df = self.connect.read.table(self.tbl_name2)
+ df2 = self.spark.read.table(self.tbl_name2)
Review Comment:
why change the table here?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]