()
| 218 | |
| 219 | |
| 220 | def test_aggregate_hash(): |
| 221 | table = pa.table({'a': [1, 2, None], 'b': ["foo", "bar", "foo"]}) |
| 222 | table_opts = TableSourceNodeOptions(table) |
| 223 | table_source = Declaration("table_source", options=table_opts) |
| 224 | |
| 225 | # default options |
| 226 | aggr_opts = AggregateNodeOptions( |
| 227 | [("a", "hash_count", None, "count(a)")], keys=["b"]) |
| 228 | decl = Declaration.from_sequence([ |
| 229 | table_source, Declaration("aggregate", aggr_opts) |
| 230 | ]) |
| 231 | result = decl.to_table() |
| 232 | expected = pa.table({"b": ["foo", "bar"], "count(a)": [1, 1]}) |
| 233 | assert result.equals(expected) |
| 234 | |
| 235 | # specify function options |
| 236 | aggr_opts = AggregateNodeOptions( |
| 237 | [("a", "hash_count", pc.CountOptions("all"), "count(a)")], keys=["b"] |
| 238 | ) |
| 239 | decl = Declaration.from_sequence([ |
| 240 | table_source, Declaration("aggregate", aggr_opts) |
| 241 | ]) |
| 242 | result = decl.to_table() |
| 243 | expected_all = pa.table({"b": ["foo", "bar"], "count(a)": [2, 1]}) |
| 244 | assert result.equals(expected_all) |
| 245 | |
| 246 | # specify keys as field references |
| 247 | aggr_opts = AggregateNodeOptions( |
| 248 | [("a", "hash_count", None, "count(a)")], keys=[field("b")] |
| 249 | ) |
| 250 | decl = Declaration.from_sequence([ |
| 251 | table_source, Declaration("aggregate", aggr_opts) |
| 252 | ]) |
| 253 | result = decl.to_table() |
| 254 | assert result.equals(expected) |
| 255 | |
| 256 | # wrong type of (aggregation) function |
| 257 | # TODO test with kernel that matches number of arguments (arity) -> avoid segfault |
| 258 | aggr_opts = AggregateNodeOptions([("a", "sum", None, "a_sum")], keys=["b"]) |
| 259 | decl = Declaration.from_sequence([ |
| 260 | table_source, Declaration("aggregate", aggr_opts) |
| 261 | ]) |
| 262 | with pytest.raises(ValueError): |
| 263 | _ = decl.to_table() |
| 264 | |
| 265 | |
| 266 | def test_order_by(): |
nothing calls this directly
no test coverage detected