| 897 | |
| 898 | |
| 899 | def test_aggregate__single_element_groups(agg_func): |
| 900 | spec = agg_func |
| 901 | |
| 902 | # nunique/cov is not supported in specs |
| 903 | if spec in ("nunique", "cov", "corr"): |
| 904 | return |
| 905 | |
| 906 | pdf = pd.DataFrame( |
| 907 | {"a": [1, 1, 3, 3], "b": [4, 4, 16, 16], "c": [1, 1, 4, 4], "d": [1, 1, 3, 3]}, |
| 908 | columns=["c", "b", "a", "d"], |
| 909 | ) |
| 910 | ddf = dd.from_pandas(pdf, npartitions=3) |
| 911 | |
| 912 | expected = pdf.groupby(["a", "d"]).agg(spec) |
| 913 | |
| 914 | # NOTE: for std the result is not recast to the original dtype |
| 915 | if spec in {"mean", "var"}: |
| 916 | expected = expected.astype(float) |
| 917 | |
| 918 | shuffle_method = ( |
| 919 | {"shuffle_method": "tasks", "split_out": 2} if agg_func == "median" else {} |
| 920 | ) |
| 921 | assert_eq(expected, ddf.groupby(["a", "d"]).agg(spec, **shuffle_method)) |
| 922 | |
| 923 | |
| 924 | def test_aggregate_build_agg_args__reuse_of_intermediates(): |