Skip to content

Commit 7a3a6c4

Browse files
parthi-sivaim-vinicius
authored and
im-vinicius
committed
TST: add test case to verify groupby-apply producing consistent output (pandas-dev#52926)
1 parent 44b6cc7 commit 7a3a6c4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pandas/tests/groupby/test_apply.py

+20
Original file line numberDiff line numberDiff line change
@@ -1485,3 +1485,23 @@ def test_empty_df(method, op):
14851485
)
14861486

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

0 commit comments

Comments
 (0)