Skip to content

Commit 76f14a2

Browse files
TomAugspurgerfangchenli
authored andcommitted
Revert BUG: Ensure same index is returned for slow and fast path in groupby.apply pandas-dev#31613 (pandas-dev#35306)
xref pandas-dev#34998
1 parent 65d5bb4 commit 76f14a2

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

doc/source/whatsnew/v1.1.0.rst

-4
Original file line numberDiff line numberDiff line change
@@ -1114,10 +1114,6 @@ Groupby/resample/rolling
11141114
- Bug in :meth:`DataFrame.resample` where an ``AmbiguousTimeError`` would be raised when the resulting timezone aware :class:`DatetimeIndex` had a DST transition at midnight (:issue:`25758`)
11151115
- Bug in :meth:`DataFrame.groupby` where a ``ValueError`` would be raised when grouping by a categorical column with read-only categories and ``sort=False`` (:issue:`33410`)
11161116
- Bug in :meth:`GroupBy.agg`, :meth:`GroupBy.transform`, and :meth:`GroupBy.resample` where subclasses are not preserved (:issue:`28330`)
1117-
- Bug in :meth:`core.groupby.DataFrameGroupBy.apply` where the output index shape for functions returning a DataFrame which is equally indexed
1118-
to the input DataFrame is inconsistent. An internal heuristic to detect index mutation would behave differently for equal but not identical
1119-
indices. In particular, the result index shape might change if a copy of the input would be returned.
1120-
The behaviour now is consistent, independent of internal heuristics. (:issue:`31612`, :issue:`14927`, :issue:`13056`)
11211117
- Bug in :meth:`SeriesGroupBy.agg` where any column name was accepted in the named aggregation of ``SeriesGroupBy`` previously. The behaviour now allows only ``str`` and callables else would raise ``TypeError``. (:issue:`34422`)
11221118
- Bug in :meth:`DataFrame.groupby` lost index, when one of the ``agg`` keys referenced an empty list (:issue:`32580`)
11231119
- Bug in :meth:`Rolling.apply` where ``center=True`` was ignored when ``engine='numba'`` was specified (:issue:`34784`)

pandas/_libs/reduction.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def apply_frame_axis0(object frame, object f, object names,
366366
# Need to infer if low level index slider will cause segfaults
367367
require_slow_apply = i == 0 and piece is chunk
368368
try:
369-
if not piece.index.equals(chunk.index):
369+
if not piece.index is chunk.index:
370370
mutated = True
371371
except AttributeError:
372372
# `piece` might not have an index, could be e.g. an int

pandas/tests/groupby/test_apply.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def test_group_apply_once_per_group2(capsys):
211211
assert result == expected
212212

213213

214+
@pytest.mark.xfail(reason="GH-34998")
214215
def test_apply_fast_slow_identical():
215216
# GH 31613
216217

@@ -234,9 +235,11 @@ def fast(group):
234235
"func",
235236
[
236237
lambda x: x,
237-
lambda x: x[:],
238+
pytest.param(lambda x: x[:], marks=pytest.mark.xfail(reason="GH-34998")),
238239
lambda x: x.copy(deep=False),
239-
lambda x: x.copy(deep=True),
240+
pytest.param(
241+
lambda x: x.copy(deep=True), marks=pytest.mark.xfail(reason="GH-34998")
242+
),
240243
],
241244
)
242245
def test_groupby_apply_identity_maybecopy_index_identical(func):
@@ -997,6 +1000,7 @@ def test_apply_function_with_indexing_return_column():
9971000
tm.assert_frame_equal(result, expected)
9981001

9991002

1003+
@pytest.mark.xfail(reason="GH-34998")
10001004
def test_apply_with_timezones_aware():
10011005
# GH: 27212
10021006

0 commit comments

Comments
 (0)