|
1 | 1 | # import flox to avoid the cost of first import
|
| 2 | +import cftime |
2 | 3 | import flox.xarray # noqa
|
3 | 4 | import numpy as np
|
4 | 5 | import pandas as pd
|
@@ -96,7 +97,7 @@ def setup(self, *args, **kwargs):
|
96 | 97 |
|
97 | 98 | requires_dask()
|
98 | 99 | super().setup(**kwargs)
|
99 |
| - self.ds1d = self.ds1d.chunk({"dim_0": 50}).to_dataframe() |
| 100 | + self.ds1d = self.ds1d.chunk({"dim_0": 50}).to_dask_dataframe() |
100 | 101 | self.ds1d_mean = self.ds1d.groupby("b").mean().compute()
|
101 | 102 |
|
102 | 103 | def time_binary_op_2d(self):
|
@@ -169,7 +170,21 @@ class GroupByLongTime:
|
169 | 170 | def setup(self, use_cftime, use_flox):
|
170 | 171 | arr = np.random.randn(10, 10, 365 * 30)
|
171 | 172 | time = xr.date_range("2000", periods=30 * 365, use_cftime=use_cftime)
|
172 |
| - self.da = xr.DataArray(arr, dims=("y", "x", "time"), coords={"time": time}) |
| 173 | + |
| 174 | + # GH9426 - deep-copying CFTime object arrays is weirdly slow |
| 175 | + asda = xr.DataArray(time) |
| 176 | + labeled_time = [] |
| 177 | + for year, month in zip(asda.dt.year, asda.dt.month, strict=True): |
| 178 | + labeled_time.append(cftime.datetime(year, month, 1)) |
| 179 | + |
| 180 | + self.da = xr.DataArray( |
| 181 | + arr, |
| 182 | + dims=("y", "x", "time"), |
| 183 | + coords={"time": time, "time2": ("time", labeled_time)}, |
| 184 | + ) |
| 185 | + |
| 186 | + def time_setup(self, use_cftime, use_flox): |
| 187 | + self.da.groupby("time.month") |
173 | 188 |
|
174 | 189 | def time_mean(self, use_cftime, use_flox):
|
175 | 190 | with xr.set_options(use_flox=use_flox):
|
|
0 commit comments