Skip to content

Commit 72ca12b

Browse files
parthi-sivatopper-123
authored andcommitted
TST: add test case to verify groupby-apply producing consistent output (pandas-dev#52926)
1 parent 13657c7 commit 72ca12b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pandas/tests/groupby/test_apply.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,3 +1484,23 @@ def test_empty_df(method, op):
14841484
)
14851485

14861486
tm.assert_series_equal(result, expected)
1487+
1488+
1489+
@pytest.mark.parametrize(
1490+
"group_col",
1491+
[([0.0, np.nan, 0.0, 0.0]), ([np.nan, 0.0, 0.0, 0.0]), ([0, 0.0, 0.0, np.nan])],
1492+
)
1493+
def test_apply_inconsistent_output(group_col):
1494+
# GH 34478
1495+
df = DataFrame({"group_col": group_col, "value_col": [2, 2, 2, 2]})
1496+
1497+
result = df.groupby("group_col").value_col.apply(
1498+
lambda x: x.value_counts().reindex(index=[1, 2, 3])
1499+
)
1500+
expected = Series(
1501+
[np.nan, 3.0, np.nan],
1502+
name="value_col",
1503+
index=MultiIndex.from_product([[0.0], [1, 2, 3]], names=["group_col", 0.0]),
1504+
)
1505+
1506+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)