def test_groupby_single_key(keygen):
np.random.seed(0)
nelem = 500
npartitions = 10
# Generate the keys
xs = keygen(nelem)
assert xs.size == nelem
df = pd.DataFrame({'x': xs,
'z': np.random.normal(size=nelem) + 1})
gdf = gd.DataFrame.from_pandas(df)
dgf = dgd.from_pygdf(gdf, npartitions=npartitions)
groups = dgf.groupby(by=['x']).count()
got = groups.compute().to_pandas()
# Check against expectation
expect = df.groupby(by=['x'], as_index=False).count()
# Check keys
np.testing.assert_array_equal(got.x, expect.x)
# Check values
np.testing.assert_array_equal(got.z, expect.z)
评论列表
文章目录