| 2256 | "transformation", [lambda x: x.sum(), np.sum, "sum", pd.Series.rank] |
| 2257 | ) |
| 2258 | def test_groupby_transform_funcs(transformation): |
| 2259 | pdf = pd.DataFrame( |
| 2260 | { |
| 2261 | "A": [1, 2, 3, 4] * 5, |
| 2262 | "B": np.random.randn(20), |
| 2263 | "C": np.random.randn(20), |
| 2264 | "D": np.random.randn(20), |
| 2265 | } |
| 2266 | ) |
| 2267 | ddf = dd.from_pandas(pdf, 3) |
| 2268 | |
| 2269 | with pytest.warns(UserWarning): |
| 2270 | # DataFrame |
| 2271 | assert_eq( |
| 2272 | pdf.groupby("A").transform(transformation), |
| 2273 | ddf.groupby("A").transform(transformation), |
| 2274 | ) |
| 2275 | |
| 2276 | # Series |
| 2277 | assert_eq( |
| 2278 | pdf.groupby("A")["B"].transform(transformation), |
| 2279 | ddf.groupby("A")["B"].transform(transformation), |
| 2280 | ) |
| 2281 | |
| 2282 | |
| 2283 | @pytest.mark.parametrize("npartitions", list(range(1, 10))) |