Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ Groupby/resample/rolling
grouped :class:`Series` or :class:`DataFrame` was a :class:`DatetimeIndex`, :class:`TimedeltaIndex`
or :class:`PeriodIndex`, and the ``groupby`` method was given a function as its first argument,
the function operated on the whole index rather than each element of the index. (:issue:`51979`)
- Bug in :meth:`DataFrame.groupby` with column selection on the resulting groupby object not returning tuples when grouping by a list of a single element. (:issue:`53500`)
- Bug in :meth:`DataFrameGroupBy.agg` with lists not respecting ``as_index=False`` (:issue:`52849`)
- Bug in :meth:`DataFrameGroupBy.apply` causing an error to be raised when the input :class:`DataFrame` was subset as a :class:`DataFrame` after groupby (``[['a']]`` and not ``['a']``) and the given callable returned :class:`Series` that were not all indexed the same. (:issue:`52444`)
- Bug in :meth:`DataFrameGroupBy.apply` raising a ``TypeError`` when selecting multiple columns and providing a function that returns ``np.ndarray`` results (:issue:`18930`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,7 @@ def _gotitem(self, key, ndim: int, subset=None):
subset = self.obj
return DataFrameGroupBy(
subset,
self.grouper,
self.keys,
axis=self.axis,
level=self.level,
grouper=self.grouper,
Expand Down
11 changes: 8 additions & 3 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2723,11 +2723,16 @@ def test_groupby_none_column_name():


def test_single_element_list_grouping():
# GH 42795
# GH#42795, GH#53500
df = DataFrame({"a": [1, 2], "b": [np.nan, 5], "c": [np.nan, 2]}, index=["x", "y"])
result = [key for key, _ in df.groupby(["a"])]
grouped = df.groupby(["a"])

result1 = [key for key, _ in grouped]
result2 = [key for key, _ in grouped[["a", "b", "c"]]]
expected = [(1,), (2,)]
assert result == expected

assert result1 == expected
assert result2 == expected


def test_groupby_string_dtype():
Expand Down