Skip to content

Commit b4a7947

Browse files
author
tascillo
committed
BUG: GroupBy.ngroup dropna=False inconsistency when using Categorical pandas-dev#50100
Wrote test case explicitly exposing issue where the result is nan
1 parent 68537e3 commit b4a7947

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pandas/tests/groupby/test_missing.py

+12
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,15 @@ def test_indices_with_missing():
153153
result = g.indices
154154
expected = {(1.0, 2): np.array([0]), (1.0, 3): np.array([1])}
155155
assert result == expected
156+
157+
158+
def test_categorical_nan_no_dropna():
159+
# GH 50100
160+
df = DataFrame.from_dict({"a": pd.Categorical([np.nan]),
161+
"b": [1]})
162+
g = df.groupby(["a", "b"], dropna=False)
163+
ng = g.ngroup()
164+
result = ng.iloc[0]
165+
expected = 0
166+
assert isinstance(result, int)
167+
assert result == expected

0 commit comments

Comments
 (0)