ueshin commented on code in PR #36148:
URL: https://github.com/apache/spark/pull/36148#discussion_r852312830


##########
python/pyspark/pandas/groupby.py:
##########
@@ -2573,15 +2631,30 @@ def stat_function(col: Column) -> Column:
         return self._reduce_for_stat_function(stat_function, 
only_numeric=numeric_only)
 
     def _reduce_for_stat_function(
-        self, sfun: Callable[[Column], Column], only_numeric: bool
+        self,
+        sfun: Callable[[Column], Column],
+        only_numeric: Optional[bool] = None,
+        bool_as_numeric: bool = False,
     ) -> FrameLike:
+        """Apply an aggregate function `sfun` per column and reduce to a 
FrameLike.
+
+        Parameters
+        ----------
+        sfun : The aggregate function to apply per column
+        only_numeric: If True, only numeric columns are involved
+        bool_as_numeric: If True, boolean columns are seen as numeric columns 
(following pandas)
+        """
         groupkey_names = [SPARK_INDEX_NAME_FORMAT(i) for i in 
range(len(self._groupkeys))]
         groupkey_scols = [s.alias(name) for s, name in 
zip(self._groupkeys_scols, groupkey_names)]
 
         agg_columns = [
             psser
             for psser in self._agg_columns
-            if isinstance(psser.spark.data_type, NumericType) or not 
only_numeric
+            if (
+                isinstance(psser.spark.data_type, NumericType)
+                or (isinstance(psser.spark.data_type, BooleanType) and 
bool_as_numeric)

Review Comment:
   nit: In that case, we might also want to move `not only_numeric` to the 
first place?



-- 
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]

Reply via email to