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

[skip-ci] Add compute to groupby benchmarks #7690

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Changes from all 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
24 changes: 13 additions & 11 deletions asv_bench/benchmarks/groupby.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# import flox to avoid the cost of first import
import flox.xarray # noqa
import numpy as np
import pandas as pd

Expand Down Expand Up @@ -27,24 +29,24 @@ def time_init(self, ndim):
@parameterized(["method", "ndim"], [("sum", "mean"), (1, 2)])
def time_agg_small_num_groups(self, method, ndim):
ds = getattr(self, f"ds{ndim}d")
getattr(ds.groupby("a"), method)()
getattr(ds.groupby("a"), method)().compute()

@parameterized(["method", "ndim"], [("sum", "mean"), (1, 2)])
def time_agg_large_num_groups(self, method, ndim):
ds = getattr(self, f"ds{ndim}d")
getattr(ds.groupby("b"), method)()
getattr(ds.groupby("b"), method)().compute()

def time_binary_op_1d(self):
self.ds1d.groupby("b") - self.ds1d_mean
(self.ds1d.groupby("b") - self.ds1d_mean).compute()

def time_binary_op_2d(self):
self.ds2d.groupby("b") - self.ds2d_mean
(self.ds2d.groupby("b") - self.ds2d_mean).compute()

def peakmem_binary_op_1d(self):
self.ds1d.groupby("b") - self.ds1d_mean
(self.ds1d.groupby("b") - self.ds1d_mean).compute()

def peakmem_binary_op_2d(self):
self.ds2d.groupby("b") - self.ds2d_mean
(self.ds2d.groupby("b") - self.ds2d_mean).compute()


class GroupByDask(GroupBy):
Expand All @@ -56,8 +58,8 @@ def setup(self, *args, **kwargs):
self.ds1d["c"] = self.ds1d["c"].chunk({"dim_0": 50})
self.ds2d = self.ds2d.sel(dim_0=slice(None, None, 2))
self.ds2d["c"] = self.ds2d["c"].chunk({"dim_0": 50, "z": 5})
self.ds1d_mean = self.ds1d.groupby("b").mean()
self.ds2d_mean = self.ds2d.groupby("b").mean()
self.ds1d_mean = self.ds1d.groupby("b").mean().compute()
self.ds2d_mean = self.ds2d.groupby("b").mean().compute()


class GroupByPandasDataFrame(GroupBy):
Expand Down Expand Up @@ -88,7 +90,7 @@ def setup(self, *args, **kwargs):
requires_dask()
super().setup(**kwargs)
self.ds1d = self.ds1d.chunk({"dim_0": 50}).to_dataframe()
self.ds1d_mean = self.ds1d.groupby("b").mean()
self.ds1d_mean = self.ds1d.groupby("b").mean().compute()
dcherian marked this conversation as resolved.
Show resolved Hide resolved

def time_binary_op_2d(self):
raise NotImplementedError
Expand Down Expand Up @@ -116,12 +118,12 @@ def time_init(self, ndim):
@parameterized(["method", "ndim"], [("sum", "mean"), (1, 2)])
def time_agg_small_num_groups(self, method, ndim):
ds = getattr(self, f"ds{ndim}d")
getattr(ds.resample(time="3M"), method)()
getattr(ds.resample(time="3M"), method)().compute()

@parameterized(["method", "ndim"], [("sum", "mean"), (1, 2)])
def time_agg_large_num_groups(self, method, ndim):
ds = getattr(self, f"ds{ndim}d")
getattr(ds.resample(time="48H"), method)()
getattr(ds.resample(time="48H"), method)().compute()


class ResampleDask(Resample):
Expand Down