@@ -1219,3 +1219,25 @@ def test_value_counts_sort_categorical(sort, vc_sort, normalize):
1219
1219
expected = expected .take (taker )
1220
1220
1221
1221
tm .assert_series_equal (result , expected )
1222
+
1223
+
1224
+ @pytest .mark .parametrize ("groupby_sort" , [True , False ])
1225
+ def test_value_counts_all_na (sort , dropna , groupby_sort ):
1226
+ # GH#59989
1227
+ df = DataFrame ({"a" : [2 , 1 , 1 ], "b" : np .nan })
1228
+ gb = df .groupby ("a" , sort = groupby_sort )
1229
+ result = gb .value_counts (sort = sort , dropna = dropna )
1230
+
1231
+ kwargs = {"levels" : [[1 , 2 ], [np .nan ]], "names" : ["a" , "b" ]}
1232
+ if dropna :
1233
+ data = []
1234
+ index = MultiIndex (codes = [[], []], ** kwargs )
1235
+ elif not groupby_sort and not sort :
1236
+ data = [1 , 2 ]
1237
+ index = MultiIndex (codes = [[1 , 0 ], [0 , 0 ]], ** kwargs )
1238
+ else :
1239
+ data = [2 , 1 ]
1240
+ index = MultiIndex (codes = [[0 , 1 ], [0 , 0 ]], ** kwargs )
1241
+ expected = Series (data , index = index , dtype = "int64" , name = "count" )
1242
+
1243
+ tm .assert_series_equal (result , expected )
0 commit comments