richacode007-byte commented on code in PR #1783:
URL: 
https://github.com/apache/datafusion-python/pull/1783#discussion_r4186421839


##########
python/tests/test_aggregation.py:
##########
@@ -555,6 +565,57 @@ def test_string_agg(name, expr, result) -> None:
     assert df.collect()[0].to_pydict() == expected
 
 
[email protected](
+    ("by_name", "by_expr"),
+    [
+        (f.count(["e"]), f.count([column("e")])),
+        (f.regr_slope("c", "a"), f.regr_slope(column("c"), column("a"))),
+        (
+            f.approx_percentile_cont("b", 0.5),
+            f.approx_percentile_cont(column("b"), 0.5),
+        ),
+        (
+            f.approx_percentile_cont_with_weight("b", "a", 0.5),
+            f.approx_percentile_cont_with_weight(column("b"), column("a"), 
0.5),
+        ),
+        (f.percentile_cont("c", 0.5), f.percentile_cont(column("c"), 0.5)),
+        (
+            f.first_value("a", order_by="c"),
+            f.first_value(column("a"), order_by="c"),
+        ),
+        (f.array_agg("a", order_by="a"), f.array_agg(column("a"), 
order_by="a")),
+        (f.bool_and("d"), f.bool_and(column("d"))),
+    ],
+)
+def test_aggregate_accepts_column_name(df, by_name, by_expr) -> None:
+    result = df.aggregate([], [by_name.alias("v")]).collect()[0]
+    expected = df.aggregate([], [by_expr.alias("v")]).collect()[0]
+    assert result == expected
+
+
+def test_string_agg_accepts_column_name() -> None:
+    ctx = SessionContext()
+    df = ctx.from_pydict({"a": ["one", "two", "three"], "b": [2, 0, 1]})
+
+    result = df.aggregate([], [f.string_agg("a", ",", 
order_by="b").alias("v")])
+
+    assert result.collect()[0].to_pydict() == {"v": ["two,three,one"]}
+
+
[email protected](
+    "build",
+    [
+        lambda: f.sum(1),
+        lambda: f.corr("a", 1),
+        lambda: f.count(["a", 1]),
+        lambda: f.approx_percentile_cont_with_weight("a", 1, 0.5),
+    ],
+)
+def test_aggregate_rejects_non_column_input(build) -> None:
+    with pytest.raises(TypeError, match="Expected Expr or column name"):
+        build()

Review Comment:
   Fair point. It mostly re-tested _to_raw_expr, which test_dataframe.py 
already covers, and it wouldn't have caught the missed grouping. I've removed 
it.



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