amol- commented on a change in pull request #11624:
URL: https://github.com/apache/arrow/pull/11624#discussion_r746782346



##########
File path: python/pyarrow/tests/test_table.py
##########
@@ -1746,3 +1746,48 @@ def test_table_select():
     result = table.select(['f2'])
     expected = pa.table([a2], ['f2'])
     assert result.equals(expected)
+
+
+def test_table_group_by():
+    table = pa.table([
+        pa.array([1, 2, 3, 4, 5]),
+        pa.array(["a", "a", "b", "b", "c"]),
+    ], names=["values", "keys"])
+
+    r = table.group_by("keys", ["values"], "hash_sum")
+    assert r.to_pydict() == {
+        "key_0": ["a", "b", "c"],
+        "sum": [3, 7, 5]
+    }
+
+    r = table.group_by("keys", ["values", "values"], [
+                       "hash_sum", "hash_count"])
+    assert r.to_pydict() == {
+        "key_0": ["a", "b", "c"],
+        "sum": [3, 7, 5],
+        "count": [2, 2, 1]
+    }

Review comment:
       You would get columns with duplicate names (two `sum` columns). At that 
point it would be hard to tell what they refer to. I did an improvement in 
https://github.com/apache/arrow/pull/11624/commits/30b64fe45bc3318ab59ad39194b5a5a12226aba9
 where column names are named after the column they refer to, so if you are 
asking two sums for two different columns you would get `col1_sum` and 
`col2_sum` making obvious what they refer to.




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