Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: User-control of result keys in GroupBy.apply #34998

Merged
merged 110 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
0fa2104
API: User-control of result keys
TomAugspurger Jun 25, 2020
13a38a2
wip
TomAugspurger Jun 26, 2020
ebb2a2d
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Jun 26, 2020
f8d646f
mmm
TomAugspurger Jun 26, 2020
623526c
updates
TomAugspurger Jun 26, 2020
6871ed0
fixups
TomAugspurger Jun 26, 2020
00ce5dc
test fixups
TomAugspurger Jun 29, 2020
c28f176
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Jun 29, 2020
c0b1140
update doctests
TomAugspurger Jun 29, 2020
cfd4d73
resample
TomAugspurger Jun 29, 2020
c05b1ea
warning
TomAugspurger Jun 29, 2020
919a4c7
remove debug
TomAugspurger Jun 29, 2020
4a45ea0
warning
TomAugspurger Jun 29, 2020
7f1478f
warning
TomAugspurger Jun 29, 2020
a1d4da8
warning
TomAugspurger Jun 29, 2020
9c229c6
wip
TomAugspurger Jun 29, 2020
f1a570b
wip
TomAugspurger Jun 30, 2020
7520dd3
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Jun 30, 2020
914c7cf
more
TomAugspurger Jun 30, 2020
7fd1a07
Add resample tests
TomAugspurger Jul 1, 2020
29f79ce
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Jul 1, 2020
76e6873
extension
TomAugspurger Jul 1, 2020
7f5cd0d
fixups
TomAugspurger Jul 1, 2020
d21dfb8
lint
TomAugspurger Jul 1, 2020
6e253c3
fix doc warning
TomAugspurger Jul 1, 2020
8efe632
lint
TomAugspurger Jul 1, 2020
bda914e
whatsnew
TomAugspurger Jul 1, 2020
3789fd7
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Jul 2, 2020
80c789e
ignore for now
TomAugspurger Jul 2, 2020
c4f6e2d
avoid mutating
TomAugspurger Jul 2, 2020
d123a80
comment on override_group_keys
TomAugspurger Jul 2, 2020
9cb58a3
fixups
TomAugspurger Jul 3, 2020
3421402
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Jul 6, 2020
2e59629
typing
TomAugspurger Jul 6, 2020
8fd0de5
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Jul 6, 2020
13965b2
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Jul 6, 2020
bfb854e
fixups
TomAugspurger Jul 6, 2020
244fec6
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Jul 6, 2020
7469b29
mypy
TomAugspurger Jul 6, 2020
16e0f5f
mypy
TomAugspurger Jul 6, 2020
4173a32
lint
TomAugspurger Jul 6, 2020
cd112cd
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Jul 7, 2020
d984e9e
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Jul 12, 2020
b6af0da
fixup
TomAugspurger Jul 12, 2020
8e46a6e
change ref
TomAugspurger Jul 12, 2020
d745c4a
fixup whatsnew
TomAugspurger Jul 12, 2020
23caf8e
fixup whatsnew
TomAugspurger Jul 12, 2020
b9b2e53
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Jul 13, 2020
3d4a744
doc
TomAugspurger Jul 13, 2020
4d984d9
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Jul 14, 2020
5d12ba4
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Aug 6, 2020
20d8520
remove xpass
TomAugspurger Aug 6, 2020
cb9217a
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Aug 7, 2020
7cf051a
Fixup
TomAugspurger Aug 7, 2020
e0972fc
Merge remote-tracking branch 'upstream/master' into 34809-result-type
TomAugspurger Sep 4, 2020
ad0f292
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
rhshadrach Jan 2, 2021
b3c8d53
merge cleanup and pass tests
rhshadrach Jan 2, 2021
08ae03f
Move docs to 1.3, avoid warnings in tests
rhshadrach Jan 3, 2021
f055193
Revert group_keys=False when apply is not used
rhshadrach Jan 3, 2021
d4f24a6
Merge branch 'master' of https://github.com/pandas-dev/pandas into 34…
rhshadrach Jan 3, 2021
c1953e6
Avoid warnings when using apply internally, bare xfail/FutureWarning …
rhshadrach Jan 3, 2021
47dec36
Merge branch 'master' of https://github.com/pandas-dev/pandas into 34…
rhshadrach Jan 3, 2021
74b98e1
Remove group_keys from DataFrame.resample, parametrize one test
rhshadrach Jan 3, 2021
a547d63
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
rhshadrach Jan 4, 2021
20d7663
Doc changes
rhshadrach Jan 4, 2021
c3bccb3
Remove group_keys from NDFrame.resample
rhshadrach Jan 4, 2021
7f7ee52
Remove group_keys from Series.resample
rhshadrach Jan 4, 2021
4f652a9
Fixed _is_indexed_like bug
rhshadrach Jan 4, 2021
499ecd4
Minor fixups
rhshadrach Jan 4, 2021
d1f2d29
whatsnew
rhshadrach Jan 4, 2021
45cd980
Restored group_keys in resample, defaults to no_default
rhshadrach Jan 9, 2021
c3f8258
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
rhshadrach Jan 9, 2021
804312a
Fixed stacklevel for resample warning, simplified test
rhshadrach Jan 9, 2021
a7d5a0e
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
rhshadrach Jan 12, 2021
a5ce219
whatsnew and docstring for DataFrame.resample
rhshadrach Jan 12, 2021
15b1556
Revert accidental changes
rhshadrach Jan 12, 2021
d3de668
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
rhshadrach Jan 26, 2021
f80c4c0
Removed unnecessary group_keys in tests
rhshadrach Jan 26, 2021
62c42e8
Removed unnecessary xfail, testing equals instead of is
rhshadrach Jan 26, 2021
bf4b126
Revert is -> eqauls change
rhshadrach Jan 27, 2021
565791a
Merge branch 'master' of https://github.com/pandas-dev/pandas into 34…
rhshadrach Nov 13, 2021
2b02b6f
fixups
rhshadrach Nov 14, 2021
3e175f9
Test fixup
rhshadrach Nov 14, 2021
7f3cc48
Update verison to 1.4.0, use find_stack_level
rhshadrach Nov 14, 2021
0c0b2c5
Cleanups
rhshadrach Nov 14, 2021
f46c59a
Added test
rhshadrach Nov 14, 2021
27ed908
type-hint fixups
rhshadrach Nov 14, 2021
1200c55
Merge branch 'master' of https://github.com/pandas-dev/pandas into 34…
rhshadrach Nov 25, 2021
d4a36b7
Merge branch '34809-result-type' of https://github.com/TomAugspurger/…
rhshadrach Nov 25, 2021
c84fa45
Doc fixups
rhshadrach Dec 5, 2021
2912d88
Merge branch '34809-result-type' of https://github.com/TomAugspurger/…
rhshadrach Dec 5, 2021
f3d94a8
Merge branch 'master' of https://github.com/pandas-dev/pandas into 34…
rhshadrach Dec 5, 2021
1bd1e0e
Merge branch 'master' of https://github.com/pandas-dev/pandas into 34…
rhshadrach Jan 1, 2022
39d54fc
Merge main
rhshadrach Jan 22, 2022
808efc4
Move notes from 1.4 to 1.5, added deprecation note for .groupby(...).…
rhshadrach Jan 22, 2022
215d9a8
Avoid warnings, is_empty_agg -> is_agg
rhshadrach Jan 22, 2022
0c8274c
Merge branch 'main' of https://github.com/pandas-dev/pandas into 3480…
rhshadrach Jan 26, 2022
c312e90
Merge branch 'main' of https://github.com/pandas-dev/pandas into 3480…
rhshadrach Jan 31, 2022
30d0f23
Merge branch 'main' of https://github.com/pandas-dev/pandas into 3480…
rhshadrach Feb 5, 2022
1c01624
Merge branch 'main' of https://github.com/pandas-dev/pandas into 3480…
rhshadrach Feb 8, 2022
14b9b0f
Suppress warning in tests
rhshadrach Feb 8, 2022
09da38e
Merge branch 'main' of https://github.com/pandas-dev/pandas into 3480…
rhshadrach Feb 13, 2022
d771ae1
Merge branch 'main' of https://github.com/pandas-dev/pandas into 3480…
rhshadrach Feb 20, 2022
cb4bed6
Merge branch 'main' of https://github.com/pandas-dev/pandas into 3480…
rhshadrach Feb 27, 2022
4ea1550
Merge branch 'main' of https://github.com/pandas-dev/pandas into 3480…
rhshadrach Mar 15, 2022
eace964
Merge branch '34809-result-type' of https://github.com/TomAugspurger/…
rhshadrach Mar 15, 2022
6407abd
Merge branch 'main' of https://github.com/pandas-dev/pandas into 3480…
rhshadrach Mar 22, 2022
deb5479
Merge branch '34809-result-type' of https://github.com/TomAugspurger/…
rhshadrach Mar 22, 2022
a0fd04c
Merge cleanup
rhshadrach Mar 23, 2022
f9aa547
Merge branch 'main' of https://github.com/pandas-dev/pandas into 3480…
rhshadrach Mar 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions doc/source/user_guide/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,14 @@ Some operations on the grouped data might not fit into either the aggregate or
transform categories. Or, you may simply want GroupBy to infer how to combine
the results. For these, use the ``apply`` function, which can be substituted
for both ``aggregate`` and ``transform`` in many standard use cases. However,
``apply`` can handle some exceptional use cases, for example:
``apply`` can handle some exceptional use cases.

.. note::

``apply`` can act as a reducer, transformer, *or* filter function, depending
on exactly what is passed to it. It can depend on the passed function and
exactly what you are grouping. Thus the grouped column(s) may be included in
the output as well as set the indices.

.. ipython:: python

Expand All @@ -1064,16 +1071,14 @@ for both ``aggregate`` and ``transform`` in many standard use cases. However,

The dimension of the returned result can also change:

.. ipython::

In [8]: grouped = df.groupby('A')['C']
.. ipython:: python
rhshadrach marked this conversation as resolved.
Show resolved Hide resolved
rhshadrach marked this conversation as resolved.
Show resolved Hide resolved

In [10]: def f(group):
....: return pd.DataFrame({'original': group,
....: 'demeaned': group - group.mean()})
....:
grouped = df.groupby('A')['C']

In [11]: grouped.apply(f)
def f(group):
return pd.DataFrame({'original': group,
'demeaned': group - group.mean()})
grouped.apply(f)
rhshadrach marked this conversation as resolved.
Show resolved Hide resolved

``apply`` on a Series can operate on a returned value from the applied function,
that is itself a series, and possibly upcast the result to a DataFrame:
Expand All @@ -1088,11 +1093,33 @@ that is itself a series, and possibly upcast the result to a DataFrame:
s
s.apply(f)

Control grouped column(s) placement with ``group_keys``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. note::

``apply`` can act as a reducer, transformer, *or* filter function, depending on exactly what is passed to it.
So depending on the path taken, and exactly what you are grouping. Thus the grouped columns(s) may be included in
the output as well as set the indices.
If ``group_keys=True`` is specified when calling :meth:`~DataFrame.groupby`,
functions passed to ``apply`` that return like-indexed outputs will have the
group keys added to the result index. Previous versions of pandas would add
the group keys only when the result from the applied function had a different
index than the input. If ``group_keys`` is not specified, the group keys will
not be added for like-indexed outputs. In the future this behavior
will change to always respect ``group_keys``, which defaults to ``True``.

.. versionchanged:: 1.5.0

To control whether the grouped column(s) are included in the indices, you can use
the argument ``group_keys``. Compare

.. ipython:: python

df.groupby("A", group_keys=True).apply(lambda x: x)

with

.. ipython:: python

df.groupby("A", group_keys=False).apply(lambda x: x)

Similar to :ref:`groupby.aggregate.udfs`, the resulting dtype will reflect that of the
apply function. If the results from different groups have different dtypes, then
Expand Down
11 changes: 8 additions & 3 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,15 @@ Now every group is evaluated only a single time.

*New behavior*:

.. ipython:: python

df.groupby("a").apply(func)
.. code-block:: python

In [3]: df.groupby('a').apply(func)
x
y
Out[3]:
a b
0 x 1
1 y 2

Concatenating sparse values
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
16 changes: 13 additions & 3 deletions doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,20 @@ result's index is not the same as the input's.

*New behavior*:

.. ipython:: python
.. code-block:: ipython

df.groupby(['a']).apply(func)
df.set_index(['a', 'b']).groupby(['a']).apply(func)
In [5]: df.groupby(['a']).apply(func)
Out[5]:
a b c
0 1 3 5
1 2 4 6

In [6]: df.set_index(['a', 'b']).groupby(['a']).apply(func)
Out[6]:
c
a b
1 3 5
2 4 6

Now in both cases it is determined that ``func`` is a transform. In each case,
the result has the same index as the input.
Expand Down
69 changes: 66 additions & 3 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,56 @@ Styler
- Added a new method :meth:`.Styler.concat` which allows adding customised footer rows to visualise additional calculations on the data, e.g. totals and counts etc. (:issue:`43875`, :issue:`46186`)
- :meth:`.Styler.highlight_null` now accepts ``color`` consistently with other builtin methods and deprecates ``null_color`` although this remains backwards compatible (:issue:`45907`)

.. _whatsnew_150.enhancements.enhancement2:
.. _whatsnew_150.enhancements.resample_group_keys:

enhancement2
^^^^^^^^^^^^
Control of index with ``group_keys`` in :meth:`DataFrame.resample`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The argument ``group_keys`` has been added to the method :meth:`DataFrame.resample`.
As with :meth:`DataFrame.groupby`, this argument controls the whether each group is added
to the index in the resample when :meth:`.Resampler.apply` is used.

.. warning::
Not specifying the ``group_keys`` argument will retain the
previous behavior and emit a warning if the result will change
by specifying ``group_keys=False``. In a future version
of pandas, not specifying ``group_keys`` will default to
the same behavior as ``group_keys=False``.

.. ipython:: python

df = pd.DataFrame(
{'a': range(6)},
index=pd.date_range("2021-01-01", periods=6, freq="8H")
)
df.resample("D", group_keys=True).apply(lambda x: x)
df.resample("D", group_keys=False).apply(lambda x: x)

Previously, the resulting index would depend upon the values returned by ``apply``,
as seen in the following example.

.. code-block:: ipython

In [1]: # pandas 1.3
In [2]: df.resample("D").apply(lambda x: x)
Out[2]:
a
2021-01-01 00:00:00 0
2021-01-01 08:00:00 1
2021-01-01 16:00:00 2
2021-01-02 00:00:00 3
2021-01-02 08:00:00 4
2021-01-02 16:00:00 5

In [3]: df.resample("D").apply(lambda x: x.reset_index())
Out[3]:
index a
2021-01-01 0 2021-01-01 00:00:00 0
1 2021-01-01 08:00:00 1
2 2021-01-01 16:00:00 2
2021-01-02 0 2021-01-02 00:00:00 3
1 2021-01-02 08:00:00 4
2 2021-01-02 16:00:00 5

.. _whatsnew_150.enhancements.other:

Expand Down Expand Up @@ -345,6 +391,23 @@ that their usage is considered unsafe, and can lead to unexpected results.

See the documentation of :class:`ExcelWriter` for further details.

.. _whatsnew_150.deprecations.group_keys_in_apply:

Using ``group_keys`` with transformers in :meth:`.GroupBy.apply`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In previous versions of pandas, if it was inferred that the function passed to
:meth:`.GroupBy.apply` was a transformer (i.e. the resulting index was equal to
the input index), the ``group_keys`` argument of :meth:`DataFrame.groupby` and
:meth:`Series.groupby` was ignored and the group keys would never be added to
the index of the result. In the future, the group keys will be added to the index
when the user specifies ``group_keys=True``.

As ``group_keys=True`` is the default value of :meth:`DataFrame.groupby` and
:meth:`Series.groupby`, not specifying ``group_keys`` with a transformer will
raise a ``FutureWarning``. This can be silenced and the previous behavior
retained by specifying ``group_keys=False``.

.. _whatsnew_150.deprecations.other:

Other Deprecations
Expand Down
25 changes: 24 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7864,6 +7864,27 @@ def update(
a 13.0 13.0
b 12.3 123.0
NaN 12.3 33.0

When using ``.apply()``, use ``group_keys`` to include or exclude the group keys.
The ``group_keys`` argument defaults to ``True`` (include).

>>> df = pd.DataFrame({'Animal': ['Falcon', 'Falcon',
... 'Parrot', 'Parrot'],
... 'Max Speed': [380., 370., 24., 26.]})
>>> df.groupby("Animal", group_keys=True).apply(lambda x: x)
rhshadrach marked this conversation as resolved.
Show resolved Hide resolved
Animal Max Speed
Animal
Falcon 0 Falcon 380.0
1 Falcon 370.0
Parrot 2 Parrot 24.0
3 Parrot 26.0

>>> df.groupby("Animal", group_keys=False).apply(lambda x: x)
Animal Max Speed
0 Falcon 380.0
1 Falcon 370.0
2 Parrot 24.0
3 Parrot 26.0
"""
)
@Appender(_shared_docs["groupby"] % _shared_doc_kwargs)
Expand All @@ -7874,7 +7895,7 @@ def groupby(
level: Level | None = None,
as_index: bool = True,
sort: bool = True,
group_keys: bool = True,
group_keys: bool | lib.NoDefault = no_default,
squeeze: bool | lib.NoDefault = no_default,
observed: bool = False,
dropna: bool = True,
Expand Down Expand Up @@ -10819,6 +10840,7 @@ def resample(
level=None,
origin: str | TimestampConvertibleTypes = "start_day",
offset: TimedeltaConvertibleTypes | None = None,
group_keys: bool | lib.NoDefault = no_default,
) -> Resampler:
return super().resample(
rule=rule,
Expand All @@ -10833,6 +10855,7 @@ def resample(
level=level,
origin=origin,
offset=offset,
group_keys=group_keys,
)

def to_timestamp(
Expand Down
13 changes: 13 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8041,6 +8041,7 @@ def resample(
level=None,
origin: str | TimestampConvertibleTypes = "start_day",
offset: TimedeltaConvertibleTypes | None = None,
group_keys: bool_t | lib.NoDefault = lib.no_default,
) -> Resampler:
"""
Resample time-series data.
Expand Down Expand Up @@ -8115,6 +8116,17 @@ def resample(

.. versionadded:: 1.1.0

group_keys : bool, optional
Whether to include the group keys in the result index when using
``.apply()`` on the resampled object. Not specifying ``group_keys``
will retain values-dependent behavior from pandas 1.4
and earlier (see :ref:`pandas 1.5.0 Release notes
<whatsnew_150.enhancements.resample_group_keys>`
for examples). In a future version of pandas, the behavior will
default to the same as specifying ``group_keys=False``.

.. versionadded:: 1.5.0

Returns
-------
pandas.core.Resampler
Expand Down Expand Up @@ -8454,6 +8466,7 @@ def resample(
level=level,
origin=origin,
offset=offset,
group_keys=group_keys,
)

@final
Expand Down
38 changes: 32 additions & 6 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def _wrap_applied_output(
data: Series,
values: list[Any],
not_indexed_same: bool = False,
override_group_keys: bool = False,
) -> DataFrame | Series:
"""
Wrap the output of SeriesGroupBy.apply into the expected result.
Expand Down Expand Up @@ -395,7 +396,11 @@ def _wrap_applied_output(
res_ser.name = self.obj.name
return res_ser
elif isinstance(values[0], (Series, DataFrame)):
return self._concat_objects(values, not_indexed_same=not_indexed_same)
return self._concat_objects(
values,
not_indexed_same=not_indexed_same,
override_group_keys=override_group_keys,
)
else:
# GH #6265 #24880
result = self.obj._constructor(
Expand Down Expand Up @@ -983,7 +988,11 @@ def _aggregate_item_by_item(self, func, *args, **kwargs) -> DataFrame:
return res_df

def _wrap_applied_output(
self, data: DataFrame, values: list, not_indexed_same: bool = False
self,
data: DataFrame,
values: list,
not_indexed_same: bool = False,
override_group_keys: bool = False,
):

if len(values) == 0:
Expand All @@ -1000,7 +1009,11 @@ def _wrap_applied_output(
# GH9684 - All values are None, return an empty frame.
return self.obj._constructor()
elif isinstance(first_not_none, DataFrame):
return self._concat_objects(values, not_indexed_same=not_indexed_same)
return self._concat_objects(
values,
not_indexed_same=not_indexed_same,
override_group_keys=override_group_keys,
)

key_index = self.grouper.result_index if self.as_index else None

Expand All @@ -1026,7 +1039,11 @@ def _wrap_applied_output(
else:
# values are Series
return self._wrap_applied_output_series(
values, not_indexed_same, first_not_none, key_index
values,
not_indexed_same,
first_not_none,
key_index,
override_group_keys,
)

def _wrap_applied_output_series(
Expand All @@ -1035,6 +1052,7 @@ def _wrap_applied_output_series(
not_indexed_same: bool,
first_not_none,
key_index,
override_group_keys: bool,
) -> DataFrame | Series:
# this is to silence a DeprecationWarning
# TODO(2.0): Remove when default dtype of empty Series is object
Expand All @@ -1058,7 +1076,11 @@ def _wrap_applied_output_series(
# if any of the sub-series are not indexed the same
# OR we don't have a multi-index and we have only a
# single values
return self._concat_objects(values, not_indexed_same=not_indexed_same)
return self._concat_objects(
values,
not_indexed_same=not_indexed_same,
override_group_keys=override_group_keys,
)

# still a series
# path added as of GH 5545
Expand All @@ -1069,7 +1091,11 @@ def _wrap_applied_output_series(

if not all_indexed_same:
# GH 8467
return self._concat_objects(values, not_indexed_same=True)
return self._concat_objects(
values,
not_indexed_same=True,
override_group_keys=override_group_keys,
)

# Combine values
# vstack+constructor is faster than concat and handles MI-columns
Expand Down
Loading