def test_serializable_groupby_agg(c, s, a, b): pd = pytest.importorskip("pandas") dd = pytest.importorskip("dask.dataframe") df = pd.DataFrame({"x": [1, 2, 3, 4], "y": [1, 0, 1, 0]}) ddf = dd.from_pandas(df, npartitions=2) result = ddf.groupby("y").agg("count") yield c.compute(result)
def test_blockwise_concatenate(c): """Test a blockwise operation with concatenated axes""" da = pytest.importorskip("dask.array") np = pytest.importorskip("numpy") def f(x, y): da.assert_eq(y, [[0, 1, 2]]) return x x = da.from_array(np.array([0, 1, 2])) y = da.from_array(np.array([[0, 1, 2]])) z = da.blockwise( f, ("i"), x, ("i"), y, ("ij"), dtype=x.dtype, concatenate=True, ) c.compute(z, optimize_graph=False) da.assert_eq(z, x, scheduler=c)
def test_predict_with_meta(client): X, y, w = generate_array(with_weights=True) partition_size = 20 margin = da.random.random(kRows, partition_size) + 1e4 dtrain = DaskDMatrix(client, X, y, weight=w, base_margin=margin) booster = xgb.dask.train( client, {}, dtrain, num_boost_round=4)['booster'] prediction = xgb.dask.predict(client, model=booster, data=dtrain) assert prediction.ndim == 1 assert prediction.shape[0] == kRows prediction = client.compute(prediction).result() assert np.all(prediction > 1e3) m = xgb.DMatrix(X.compute()) m.set_info(label=y.compute(), weight=w.compute(), base_margin=margin.compute()) single = booster.predict(m) # Make sure the ordering is correct. assert np.all(prediction == single)