Skip to content

Commit ad746ba

Browse files
committed
update mgr_locs
1 parent 5007426 commit ad746ba

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

pandas/_libs/reduction.pyx

+2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ cdef class _BaseGrouper:
177177
object.__setattr__(cached_ityp, '_index_data', islider.buf)
178178
cached_ityp._engine.clear_mapping()
179179
object.__setattr__(cached_typ._data._block, 'values', vslider.buf)
180+
object.__setattr__(cached_typ._data._block, 'mgr_locs',
181+
slice(len(vslider.buf)))
180182
object.__setattr__(cached_typ, '_index', cached_ityp)
181183
object.__setattr__(cached_typ, 'name', self.name)
182184

pandas/tests/groupby/test_bin_groupby.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,18 @@ def cumsum_max(x):
6262
return 0
6363

6464

65-
@pytest.mark.parametrize(
66-
"func",
67-
[
68-
cumsum_max,
69-
pytest.param(assert_block_lengths, marks=pytest.mark.xfail(reason="debatable")),
70-
],
71-
)
72-
def test_operation_on_invalid_block_passes(func):
65+
@pytest.mark.parametrize("func", [cumsum_max, assert_block_lengths])
66+
def test_mgr_locs_updated(func):
7367
# https://github.com/pandas-dev/pandas/issues/31802
74-
# SeriesBinGrouper creates an invalid block, which may
75-
# raise arbitrary exceptions.
68+
# Some operations may require creating new blocks, which requires
69+
# valid mgr_locs
7670
df = pd.DataFrame({"A": ["a", "a", "a"], "B": ["a", "b", "b"], "C": [1, 1, 1]})
7771
result = df.groupby(["A", "B"]).agg(func)
78-
assert isinstance(result, pd.DataFrame)
72+
expected = pd.DataFrame(
73+
{"C": [0, 0]},
74+
index=pd.MultiIndex.from_product([["a"], ["a", "b"]], names=["A", "B"]),
75+
)
76+
tm.assert_frame_equal(result, expected)
7977

8078

8179
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)