Skip to content

Commit 8b60ebb

Browse files
adamhooperjreback
authored andcommitted
BUG: GroupBy.size with all-null data raises ValueError (#26112)
1 parent df1fb03 commit 8b60ebb

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ Groupby/Resample/Rolling
381381
- Bug in :meth:`pandas.core.groupby.DataFrameGroupBy.nunique` in which the names of column levels were lost (:issue:`23222`)
382382
- Bug in :func:`pandas.core.groupby.GroupBy.agg` when applying a aggregation function to timezone aware data (:issue:`23683`)
383383
- Bug in :func:`pandas.core.groupby.GroupBy.first` and :func:`pandas.core.groupby.GroupBy.last` where timezone information would be dropped (:issue:`21603`)
384+
- Bug in :func:`pandas.core.groupby.GroupBy.size` when grouping only NA values (:issue:`23050`)
384385
- Bug in :func:`Series.groupby` where using ``groupby`` with a :class:`MultiIndex` Series with a list of labels equal to the length of the series caused incorrect grouping (:issue:`25704`)
385386
- Ensured that ordering of outputs in ``groupby`` aggregation functions is consistent across all versions of Python (:issue:`25692`)
386387
- Ensured that result group order is correct when grouping on an ordered ``Categorical`` and specifying ``observed=True`` (:issue:`25871`, :issue:`25167`)

pandas/core/groupby/ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def size(self):
246246
if ngroup:
247247
out = np.bincount(ids[ids != -1], minlength=ngroup)
248248
else:
249-
out = ids
249+
out = []
250250
return Series(out,
251251
index=self.result_index,
252252
dtype='int64')

pandas/tests/groupby/test_function.py

+9
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,15 @@ def test_size(df):
10901090
tm.assert_series_equal(df.groupby('A').size(), out)
10911091

10921092

1093+
def test_size_groupby_all_null():
1094+
# GH23050
1095+
# Assert no 'Value Error : Length of passed values is 2, index implies 0'
1096+
df = DataFrame({'A': [None, None]}) # all-null groups
1097+
result = df.groupby('A').size()
1098+
expected = Series(dtype='int64', index=Index([], name='A'))
1099+
tm.assert_series_equal(result, expected)
1100+
1101+
10931102
# quantile
10941103
# --------------------------------
10951104
@pytest.mark.parametrize("interpolation", [

0 commit comments

Comments
 (0)