Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create benchmark for groupby #5772

Merged
merged 4 commits into from
Sep 20, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions asv_bench/benchmarks/groupby.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import numpy as np

import xarray as xr

from . import parameterized, requires_dask


class GroupBy:
def setup(self, *args, **kwargs):
self.ds = xr.Dataset(
{
"a": xr.DataArray(np.r_[np.arange(500.0), np.arange(500.0)]),
"b": xr.DataArray(np.arange(1000.0)),
}
)

@parameterized(["method"], [("sum", "mean")])
def agg(self, method):
dcherian marked this conversation as resolved.
Show resolved Hide resolved
return getattr(self.ds.groupby("a"), method)()


class GroupByDask(GroupBy):
def setup(self, *args, **kwargs):
requires_dask()
super().setup(**kwargs)
self.ds = self.ds.chunk({"dim_0": 50})


class GroupByDataFrame(GroupBy):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we really need the dataframe tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good to have some kind of "competitor" comparison, because performance complaints will always be relative to them anyway. It might not be needed for more than just a few of the (future) tests though.

def setup(self, *args, **kwargs):
super().setup(**kwargs)
self.ds = self.ds.to_dataframe()


class GroupByDaskDataFrame(GroupBy):
def setup(self, *args, **kwargs):
requires_dask()
super().setup(**kwargs)
self.ds = self.ds.chunk({"dim_0": 50}).to_dataframe()