Skip to content

Commit e917385

Browse files
add test for groupby on complex numbers
1 parent 4ac340e commit e917385

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/tests/groupby/test_groupby.py

+13
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ def test_basic_aggregations(dtype):
136136
grouped.aggregate(lambda x: x * 2)
137137

138138

139+
def test_groupby_complex_numbers():
140+
df = DataFrame([
141+
{"a": 2, "b": 1 + 2j},
142+
{"a": 1, "b": 1 + 1j},
143+
{"a": 1, "b": 1 + 2j},
144+
])
145+
assert df.groupby("b").groups == {(1 + 1j): [1], (1 + 2j): [0, 2]}
146+
tm.assert_frame_equal(
147+
df.groupby("b").mean(),
148+
DataFrame({"a": {(1 + 1j): 1.0, (1 + 2j): 1.5}}),
149+
)
150+
151+
139152
def test_groupby_nonobject_dtype(multiindex_dataframe_random_data):
140153
key = multiindex_dataframe_random_data.index.codes[0]
141154
grouped = multiindex_dataframe_random_data.groupby(key)

0 commit comments

Comments
 (0)