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


##########
python/pyspark/pandas/tests/test_groupby.py:
##########
@@ -1242,6 +1242,54 @@ def test_rank(self):
             pdf.groupby([("x", "a"), ("x", "b")]).rank().sort_index(),
         )
 
+    def test_min(self):
+        pdf = pd.DataFrame(
+            {
+                "A": [1, 2, 1, 2],
+                "B": [3, 4, 4, 3],

Review Comment:
   ```suggestion
                   "B": [3.1, 4.1, 4.1, 3.1],
   ```
   
   nit: we might easy to cover `float, int, boolean columns` by change this



##########
python/pyspark/pandas/tests/test_groupby.py:
##########
@@ -1242,6 +1242,54 @@ def test_rank(self):
             pdf.groupby([("x", "a"), ("x", "b")]).rank().sort_index(),
         )
 
+    def test_min(self):
+        pdf = pd.DataFrame(
+            {
+                "A": [1, 2, 1, 2],
+                "B": [3, 4, 4, 3],
+                "C": ["a", "b", "b", "a"],
+                "D": [True, False, False, True],
+            }
+        )
+        psdf = ps.from_pandas(pdf)
+        for p_groupby_obj, ps_groupby_obj in [
+            (pdf.groupby("A"), psdf.groupby("A")),
+            (pdf.groupby("A")[["C"]], psdf.groupby("A")[["C"]]),
+        ]:
+            self.assert_eq(p_groupby_obj.min().sort_index(), 
ps_groupby_obj.min().sort_index())
+            self.assert_eq(
+                p_groupby_obj.min(numeric_only=None).sort_index(),
+                ps_groupby_obj.min(numeric_only=None).sort_index(),
+            )
+            self.assert_eq(
+                p_groupby_obj.min(numeric_only=True).sort_index(),
+                ps_groupby_obj.min(numeric_only=True).sort_index(),
+            )
+
+    def test_max(self):
+        pdf = pd.DataFrame(
+            {
+                "A": [1, 2, 1, 2],
+                "B": [3, 4, 4, 3],

Review Comment:
   ```suggestion
                   "B": [3.1, 4.1, 4.1, 3.1],
   ```
   
   same



##########
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:
   ```suggestion
                   or (bool_as_numeric and isinstance(psser.spark.data_type, 
BooleanType))
   ```
   
   super nits: this might reduce isinstance cost by short-circuiting, fine for 
me if you think it's no need to change.



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