Skip to content

Commit

Permalink
Small improvement to resampling
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Nov 26, 2021
1 parent 4f378a3 commit af03ca4
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ def _maybe_unstack(self, obj):
def _flox_reduce(self, dim, **kwargs):
from flox.xarray import xarray_reduce

from .dataarray import DataArray
from .dataset import Dataset

# TODO: fix this
Expand All @@ -555,19 +556,17 @@ def _flox_reduce(self, dim, **kwargs):
# TODO: only do this for resample, not general groupers...
# this creates a label DataArray since resample doesn't do that somehow
if isinstance(self._group_indices[0], slice):
from .dataarray import DataArray

tostack = []
for idx, slicer in zip(self._unique_coord.data, self._group_indices):
if slicer.stop is None:
stop = self._obj.sizes[self._group_dim]
else:
stop = slicer.stop
tostack.append(np.full((stop - slicer.start,), fill_value=idx))
repeats = []
for slicer in self._group_indices:
stop = (
slicer.stop
if slicer.stop is not None
else self._obj.sizes[self._group_dim]
)
repeats.append(stop - slicer.start)
labels = np.repeat(self._unique_coord.data, repeats)
group = DataArray(
np.hstack(tostack),
dims=(self._group_dim,),
name=self._unique_coord.name,
labels, dims=(self._group_dim,), name=self._unique_coord.name
)
else:
if isinstance(self._unstacked_group, _DummyGroup):
Expand Down Expand Up @@ -603,7 +602,7 @@ def _flox_reduce(self, dim, **kwargs):

if self._bins is not None:
# bins provided to dask_groupby are at full precision
# the bin edge labels a default precision of 3
# the bin edge labels have a default precision of 3
# reassign to fix that.
new_coord = [
pd.Interval(inter.left, inter.right) for inter in self._full_index
Expand Down

0 comments on commit af03ca4

Please sign in to comment.