Skip to content

Commit 085abb2

Browse files
committed
Tests added for PR #36605
Bug in issue #36158 appeared both for indices and get_group().
1 parent 7332b24 commit 085abb2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/groupby/test_grouping.py

+19
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ def test_getitem_single_column(self):
124124

125125
tm.assert_series_equal(result, expected)
126126

127+
def test_indices_grouped_by_tuple_with_lambda(self):
128+
df = pd.DataFrame({'Tuples': ((x, y)
129+
for x in [0, 1]
130+
for y in np.random.randint(3, 5, 5))})
131+
gb = df.groupby('Tuples')
132+
gb_lambda = df.groupby(lambda x: df.iloc[x, 0])
133+
expected = gb.indices
134+
result = gb_lambda.indices
135+
tm.assert_dict_equal(result, expected)
127136

128137
# grouping
129138
# --------------------------------
@@ -775,6 +784,16 @@ def test_get_group_grouped_by_tuple(self):
775784
expected = DataFrame({"ids": [(dt[0],), (dt[0],)]}, index=[0, 2])
776785
tm.assert_frame_equal(result, expected)
777786

787+
def test_get_group_grouped_by_tuple_with_lambda(self):
788+
df = pd.DataFrame({'Tuples': ((x, y)
789+
for x in [0, 1]
790+
for y in np.random.randint(3, 5, 5))})
791+
gb = df.groupby('Tuples')
792+
gb_lambda = df.groupby(lambda x: df.iloc[x, 0])
793+
expected = gb.get_group(list(gb.groups.keys())[0])
794+
result = gb_lambda.get_group(list(gb_lambda.groups.keys())[0])
795+
tm.assert_frame_equal(result, expected)
796+
778797
def test_groupby_with_empty(self):
779798
index = pd.DatetimeIndex(())
780799
data = ()

0 commit comments

Comments
 (0)