File tree 3 files changed +13
-2
lines changed
3 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -461,7 +461,7 @@ Sparse
461
461
ExtensionArray
462
462
^^^^^^^^^^^^^^
463
463
464
- -
464
+ - Fixed bug where :meth: ` Serires.value_counts ` would raise on empty input of `` Int64 `` dtype ( :issue: ` 33317 `)
465
465
-
466
466
467
467
Original file line number Diff line number Diff line change @@ -499,7 +499,8 @@ def _values_for_argsort(self) -> np.ndarray:
499
499
ExtensionArray.argsort
500
500
"""
501
501
data = self ._data .copy ()
502
- data [self ._mask ] = data .min () - 1
502
+ if self ._mask .any ():
503
+ data [self ._mask ] = data .min () - 1
503
504
return data
504
505
505
506
@classmethod
Original file line number Diff line number Diff line change @@ -103,6 +103,16 @@ def test_value_counts_na():
103
103
tm .assert_series_equal (result , expected )
104
104
105
105
106
+ def test_value_counts_empty ():
107
+ # https://github.com/pandas-dev/pandas/issues/33317
108
+ s = pd .Series ([], dtype = "Int64" )
109
+ result = s .value_counts ()
110
+ # TODO: The dtype of the index seems wrong (it's int64 for non-empty)
111
+ idx = pd .Index ([], dtype = "object" )
112
+ expected = pd .Series ([], index = idx , dtype = "Int64" )
113
+ tm .assert_series_equal (result , expected )
114
+
115
+
106
116
# TODO(jreback) - these need testing / are broken
107
117
108
118
# shift
You can’t perform that action at this time.
0 commit comments