Skip to content

Segfault in .groupby() with empty groups #1048

Closed
@twiecki

Description

@twiecki

I get a segfault when running:

pandas.DataFrame([1,2,3]).groupby([]).groups

As an aside, in my scenario (which I don't know how general it is) the user can supply the grouping. If no grouping should take place (i.e. groupby([])) I would like .groupby() to return the whole data, instead there is a:

/usr/local/lib/python2.7/dist-packages/pandas/core/groupby.pyc in _get_compressed_labels(self)
547 group_index = get_group_index(all_labels, self.shape)
548 else:
--> 549 group_index = all_labels[0]
550 comp_ids, obs_group_ids = _compress_group_index(group_index)
551 return comp_ids, obs_group_ids

IndexError: list index out of range

I'm not sure whether it would be sensible to change the behavior so that the whole DataFrame is returned, but to me it would be more useful than raising an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions