Skip to content

Commit

Permalink
Check easily made user mistake for count_ etc. (#4590)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmao-denver authored Oct 3, 2023
1 parent 70b4e27 commit 8f89025
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions py/server/deephaven/agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def count_(col: str) -> Aggregation:
Returns:
an aggregation
"""
if not isinstance(col, str):
raise DHError(message="count_ aggregation requires a string value for the 'col' argument.")
return Aggregation(j_aggregation=_JAggregation.AggCount(col))


Expand All @@ -119,6 +121,8 @@ def partition(col: str, include_by_columns: bool = True) -> Aggregation:
Returns:
an aggregation
"""
if not isinstance(col, str):
raise DHError(message="partition aggregation requires a string value for the 'col' argument.")
return Aggregation(j_aggregation=_JAggregation.AggPartition(col, include_by_columns))


Expand Down
10 changes: 10 additions & 0 deletions py/server/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,16 @@ def test_has_columns(self):
self.assertFalse(t.has_columns("D"))
self.assertFalse(t.has_columns(["D", "C"]))

def test_agg_count_and_partition_error(self):
t = empty_table(1).update(["A=i", "B=i", "C=i"])
with self.assertRaises(DHError) as cm:
t.agg_by(aggs=count_(["A"]), by=["B"])
self.assertIn("string value", str(cm.exception))

with self.assertRaises(DHError) as cm:
t.agg_by(aggs=[partition(["A"])], by=["B"])
self.assertIn("string value", str(cm.exception))


if __name__ == "__main__":
unittest.main()

0 comments on commit 8f89025

Please sign in to comment.