Skip to content

Commit 7a468b0

Browse files
dsaxtonjbrockmendel
authored andcommitted
BUG: Don't raise on value_counts for empty Int64 (pandas-dev#33339)
1 parent fcfa7c4 commit 7a468b0

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

doc/source/whatsnew/v1.1.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ Sparse
461461
ExtensionArray
462462
^^^^^^^^^^^^^^
463463

464-
-
464+
- Fixed bug where :meth:`Serires.value_counts` would raise on empty input of ``Int64`` dtype (:issue:`33317`)
465465
-
466466

467467

pandas/core/arrays/integer.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ def _values_for_argsort(self) -> np.ndarray:
499499
ExtensionArray.argsort
500500
"""
501501
data = self._data.copy()
502-
data[self._mask] = data.min() - 1
502+
if self._mask.any():
503+
data[self._mask] = data.min() - 1
503504
return data
504505

505506
@classmethod

pandas/tests/arrays/integer/test_function.py

+10
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ def test_value_counts_na():
103103
tm.assert_series_equal(result, expected)
104104

105105

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+
106116
# TODO(jreback) - these need testing / are broken
107117

108118
# shift

0 commit comments

Comments
 (0)