jorisvandenbossche commented on a change in pull request #11624:
URL: https://github.com/apache/arrow/pull/11624#discussion_r752350554



##########
File path: python/pyarrow/table.pxi
##########
@@ -2387,3 +2429,60 @@ def _from_pydict(cls, mapping, schema, metadata):
         return cls.from_arrays(arrays, schema=schema, metadata=metadata)
     else:
         raise TypeError('Schema must be an instance of pyarrow.Schema')
+
+
+class TableGroupBy:
+    """
+    A grouping of columns in a table on which to perform aggregations.
+    """
+
+    def __init__(self, table, keys):
+        if isinstance(keys, str):
+            keys = [keys]
+
+        self._table = table
+        self.keys = keys
+
+    def aggregate(self, aggregations):
+        """
+        Perform an aggregation over the grouped columns of the table.
+
+        Parameters
+        ----------
+        aggregations : list[tuple(str, str)] or\
+                       list[tuple(str, str, FunctionOptions)]

Review comment:
       ```suggestion
           aggregations : list[tuple(str, str)] or \
   list[tuple(str, str, FunctionOptions)]
   ```
   
   (ugly, but that's what is needed to have the actual docstring look good)

##########
File path: python/pyarrow/table.pxi
##########
@@ -2387,3 +2429,60 @@ def _from_pydict(cls, mapping, schema, metadata):
         return cls.from_arrays(arrays, schema=schema, metadata=metadata)
     else:
         raise TypeError('Schema must be an instance of pyarrow.Schema')
+
+
+class TableGroupBy:
+    """
+    A grouping of columns in a table on which to perform aggregations.
+    """
+
+    def __init__(self, table, keys):
+        if isinstance(keys, str):
+            keys = [keys]
+
+        self._table = table
+        self.keys = keys
+
+    def aggregate(self, aggregations):
+        """
+        Perform an aggregation over the grouped columns of the table.
+
+        Parameters
+        ----------
+        aggregations : list[tuple(str, str)] or\
+                       list[tuple(str, str, FunctionOptions)]
+            List of tuples made of aggregation functions names followed
+            by column names and optionally aggregation function options.

Review comment:
       Also, I think it would be good to give a small example here (just to see 
it visually, something like ```for example ``[("col_A", "sum"), ("col_B", 
"min", options)]`` ```

##########
File path: python/pyarrow/table.pxi
##########
@@ -2387,3 +2429,60 @@ def _from_pydict(cls, mapping, schema, metadata):
         return cls.from_arrays(arrays, schema=schema, metadata=metadata)
     else:
         raise TypeError('Schema must be an instance of pyarrow.Schema')
+
+
+class TableGroupBy:
+    """
+    A grouping of columns in a table on which to perform aggregations.
+    """
+
+    def __init__(self, table, keys):
+        if isinstance(keys, str):
+            keys = [keys]
+
+        self._table = table
+        self.keys = keys
+
+    def aggregate(self, aggregations):
+        """
+        Perform an aggregation over the grouped columns of the table.
+
+        Parameters
+        ----------
+        aggregations : list[tuple(str, str)] or\
+                       list[tuple(str, str, FunctionOptions)]
+            List of tuples made of aggregation functions names followed
+            by column names and optionally aggregation function options.

Review comment:
       Would it make more sense to do this the other way around? 
   Now you have `("func", "col", options)`, but so `("col", "func", options)`.
   
   This way the function name and options are closer together (if the options 
are specified). That order also matches the resulting name (which is 
"col_func"). And it also matches the order in pandas I think.
   




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


Reply via email to