Skip to content

Commit 0bf986e

Browse files
committed
add test for Series.groupby
1 parent 47cabb2 commit 0bf986e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pandas/tests/groupby/test_groupby_dropna.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,34 @@ def test_groupby_nan_included_warns(by, dropna):
421421
result = grouped.indices # noqa:F841
422422

423423

424+
@pytest.mark.parametrize(
425+
"by_type",
426+
[
427+
"level",
428+
"argument",
429+
],
430+
)
431+
@pytest.mark.parametrize("dropna", [True, False, None])
432+
def test_groupby_series_nan_included_warns(by_type, dropna):
433+
# GH 61339
434+
index = ["a", "a", "b", np.nan]
435+
ser = pd.Series([1, 2, 3, 3])
436+
437+
if by_type == "level":
438+
ser = ser.set_axis(index, axis=0)
439+
kwargs = {"level": 0}
440+
elif by_type == "argument":
441+
kwargs = {"by": index}
442+
443+
warning_type = pd.errors.NullKeyWarning
444+
if dropna is not None:
445+
kwargs["dropna"] = dropna
446+
warning_type = None
447+
448+
with tm.assert_produces_warning(warning_type):
449+
ser.groupby(**kwargs).sum()
450+
451+
424452
def test_groupby_drop_nan_with_multi_index():
425453
# GH 39895
426454
df = pd.DataFrame([[np.nan, 0, 1]], columns=["a", "b", "c"])

0 commit comments

Comments
 (0)