Skip to content

Commit 36a3769

Browse files
committed
Fix grouping by datetime
1 parent 915a91b commit 36a3769

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

flox/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def find_group_cohorts(labels, chunks, merge=True, method="cohorts"):
162162
labels = np.asarray(labels)
163163

164164
if method == "split-reduce":
165-
return _get_expected_groups(labels, sort=False).values.reshape(-1, 1).tolist()
165+
return list(_get_expected_groups(labels, sort=False).to_numpy().reshape(-1, 1))
166166

167167
# Build an array with the shape of labels, but where every element is the "chunk number"
168168
# 1. First subset the array appropriately
@@ -1225,7 +1225,7 @@ def dask_groupby_agg(
12251225
if method == "map-reduce":
12261226
if expected_groups is None:
12271227
expected_groups = _get_expected_groups(by_input, sort=sort)
1228-
groups = (expected_groups.values,)
1228+
groups = (expected_groups.to_numpy(),)
12291229
else:
12301230
groups = (np.concatenate(groups_in_block),)
12311231

tests/test_core.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,3 +853,19 @@ def test_map_reduce_blockwise_mixed():
853853
)
854854
expected = groupby_reduce(data, t.dt.month, func="mean")
855855
assert_equal(expected, actual)
856+
857+
858+
@requires_dask
859+
@pytest.mark.parametrize("method", ["blockwise", "split-reduce", "map-reduce", "cohorts"])
860+
def test_group_by_datetime(engine, method):
861+
t = pd.date_range("2000-01-01", "2000-12-31", freq="D").to_series()
862+
data = t.dt.dayofyear
863+
actual, _ = groupby_reduce(
864+
dask.array.from_array(data.values, chunks=365),
865+
t,
866+
func="mean",
867+
method=method,
868+
engine=engine,
869+
)
870+
expected = data.to_numpy().astype(float)
871+
assert_equal(expected, actual)

0 commit comments

Comments
 (0)