|
1 | 1 | import numpy as np
|
| 2 | +import pytest |
2 | 3 |
|
3 | 4 | import pandas as pd
|
4 | 5 | from pandas import Categorical, CategoricalIndex, Series
|
@@ -177,3 +178,28 @@ def test_value_counts_categorical_with_nan(self):
|
177 | 178 | exp = Series([2, 1, 3], index=CategoricalIndex(["a", "b", np.nan]))
|
178 | 179 | res = ser.value_counts(dropna=False, sort=False)
|
179 | 180 | tm.assert_series_equal(res, exp)
|
| 181 | + |
| 182 | + @pytest.mark.parametrize( |
| 183 | + "ser, dropna, exp", |
| 184 | + [ |
| 185 | + ( |
| 186 | + pd.Series([False, True, True, pd.NA]), |
| 187 | + False, |
| 188 | + pd.Series([2, 1, 1], index=[True, False, pd.NA]), |
| 189 | + ), |
| 190 | + ( |
| 191 | + pd.Series([False, True, True, pd.NA]), |
| 192 | + True, |
| 193 | + pd.Series([2, 1], index=[True, False]), |
| 194 | + ), |
| 195 | + ( |
| 196 | + pd.Series(range(3), index=[True, False, np.nan]).index, |
| 197 | + False, |
| 198 | + pd.Series([1, 1, 1], index=[True, False, pd.NA]), |
| 199 | + ), |
| 200 | + ], |
| 201 | + ) |
| 202 | + def test_value_counts_bool_with_nan(self, ser, dropna, exp): |
| 203 | + # GH32146 |
| 204 | + out = ser.value_counts(dropna=dropna) |
| 205 | + tm.assert_series_equal(out, exp) |
0 commit comments