Skip to content

Commit 4d1abac

Browse files
committed
BUG: BooleanArray.value_counts dropna
Closes pandas-dev#30685
1 parent 4a039c6 commit 4d1abac

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pandas/core/arrays/boolean.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,8 @@ def value_counts(self, dropna=True):
628628
# w/o passing the dtype
629629
array = np.append(array, [self._mask.sum()])
630630
index = Index(
631-
np.concatenate([index, np.array([np.nan], dtype=object)]), dtype=object
631+
np.concatenate([index, np.array([self.dtype.na_value], dtype=object)]),
632+
dtype=object,
632633
)
633634

634635
return Series(array, index=index)

pandas/tests/arrays/test_boolean.py

+7
Original file line numberDiff line numberDiff line change
@@ -856,3 +856,10 @@ def test_arrow_roundtrip():
856856
result = table.to_pandas()
857857
assert isinstance(result["a"].dtype, pd.BooleanDtype)
858858
tm.assert_frame_equal(result, df)
859+
860+
861+
def test_value_counts_na():
862+
arr = pd.array([True, False, pd.NA], dtype="boolean")
863+
result = arr.value_counts(dropna=False)
864+
expected = pd.Series([1, 1, 1], index=[True, False, pd.NA])
865+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)