@@ -190,8 +190,22 @@ def test_value_counts_bins(index_or_series):
190
190
191
191
assert s .nunique () == 0
192
192
193
- # handle normalizing bins with NA's properly
194
- # see GH25970
193
+
194
+ def test_value_counts_bins_nas ():
195
+ # GH25970, handle normalizing bins with NA's properly
196
+ # First test that NA's are included appropriately
197
+ rand_data = np .append (
198
+ np .random .randint (1 , 5 , 50 ), [np .nan ] * np .random .randint (1 , 20 )
199
+ )
200
+ s = Series (rand_data )
201
+ assert s .value_counts (dropna = False ).index .hasnans
202
+ assert not s .value_counts (dropna = True ).index .hasnans
203
+ assert s .value_counts (dropna = False , bins = 3 ).index .hasnans
204
+ assert not s .value_counts (dropna = True , bins = 3 ).index .hasnans
205
+ assert s .value_counts (dropna = False , bins = [0 , 1 , 3 , 6 ]).index .hasnans
206
+ assert not s .value_counts (dropna = True , bins = [0 , 1 , 3 , 6 ]).index .hasnans
207
+
208
+ # then verify specific example
195
209
s2 = Series ([1 , 2 , 2 , 3 , 3 , 3 , np .nan , np .nan , 4 , 5 ])
196
210
intervals = IntervalIndex .from_breaks ([0.995 , 2.333 , 3.667 , 5.0 ])
197
211
expected_dropna = Series ([0.375 , 0.375 , 0.25 ], intervals .take ([1 , 0 , 2 ]))
0 commit comments