Skip to content

Commit 93359af

Browse files
authored
TST: added test with missing categories for value_counts (#54837)
1 parent a720c69 commit 93359af

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/tests/frame/methods/test_value_counts.py

+14
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,17 @@ def test_value_counts_categorical_future_warning():
189189
name="count",
190190
)
191191
tm.assert_series_equal(result, expected)
192+
193+
194+
def test_value_counts_with_missing_category():
195+
# GH-54836
196+
df = pd.DataFrame({"a": pd.Categorical([1, 2, 4], categories=[1, 2, 3, 4])})
197+
result = df.value_counts()
198+
expected = pd.Series(
199+
[1, 1, 1, 0],
200+
index=pd.MultiIndex.from_arrays(
201+
[pd.CategoricalIndex([1, 2, 4, 3], categories=[1, 2, 3, 4], name="a")]
202+
),
203+
name="count",
204+
)
205+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)