Skip to content

Commit 9a34ad1

Browse files
committed
BUG: raise error for groupby() with invalid tuple key
closes pandas-dev#18798
1 parent b6a7cc9 commit 9a34ad1

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

doc/source/whatsnew/v0.22.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ Groupby/Resample/Rolling
310310
^^^^^^^^^^^^^^^^^^^^^^^^
311311

312312
- Bug when grouping by a single column and aggregating with a class like ``list`` or ``tuple`` (:issue:`18079`)
313+
- Fixed regression in :func:`DataFrame.groupby` which would not emit an error when called with a tuple key not in the index (:issue:`18798`)
313314
-
314315
-
315316

pandas/core/groupby.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2978,7 +2978,8 @@ def is_in_obj(gpr):
29782978

29792979
def _is_label_like(val):
29802980
return (isinstance(val, compat.string_types) or
2981-
(val is not None and is_scalar(val)))
2981+
(val is not None and is_scalar(val)) or
2982+
isinstance(val, tuple))
29822983

29832984

29842985
def _convert_grouper(axis, grouper):

pandas/tests/groupby/test_groupby.py

-1
Original file line numberDiff line numberDiff line change
@@ -2750,7 +2750,6 @@ def test_tuple_warns_unhashable(self):
27502750

27512751
assert "Interpreting tuple 'by' as a list" in str(w[0].message)
27522752

2753-
@pytest.mark.xfail(reason="GH-18798")
27542753
def test_tuple_correct_keyerror(self):
27552754
# https://github.com/pandas-dev/pandas/issues/18798
27562755
df = pd.DataFrame(1, index=range(3),

0 commit comments

Comments
 (0)