Skip to content

Commit 6b7578b

Browse files
Add test for unique aggregation returning different dtypes (#47603)
* TST: Added test for consistent type with unique agg #22558 * TST: Added test for consistent type with unique agg #22558 * TST: Moved and restructured test #22558 * TST: Moved test to different file #22558 * TST: Changed scalars to 1-element lists Co-authored-by: Steven Rotondo <[email protected]>
1 parent 45a38c6 commit 6b7578b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/apply/test_frame_apply.py

+18
Original file line numberDiff line numberDiff line change
@@ -1585,3 +1585,21 @@ def test_apply_on_empty_dataframe():
15851585
result = df.head(0).apply(lambda x: max(x["a"], x["b"]), axis=1)
15861586
expected = Series([])
15871587
tm.assert_series_equal(result, expected)
1588+
1589+
1590+
@pytest.mark.parametrize(
1591+
"test, constant",
1592+
[
1593+
({"a": [1, 2, 3], "b": [1, 1, 1]}, {"a": [1, 2, 3], "b": [1]}),
1594+
({"a": [2, 2, 2], "b": [1, 1, 1]}, {"a": [2], "b": [1]}),
1595+
],
1596+
)
1597+
def test_unique_agg_type_is_series(test, constant):
1598+
# GH#22558
1599+
df1 = DataFrame(test)
1600+
expected = Series(data=constant, index=["a", "b"], dtype="object")
1601+
aggregation = {"a": "unique", "b": "unique"}
1602+
1603+
result = df1.agg(aggregation)
1604+
1605+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)