A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/8121 below:

get_group sometimes throws an exception when using an index of tuples with different lengths · Issue #8121 · pandas-dev/pandas · GitHub

Here is a simple test case that exposes the problem:

    df = pd.DataFrame(pd.Series([(1,), (1,2), (1,), (1, 2)]), columns = ['ids'])
    gb = df.groupby('ids')
    for i in gb.size().index :
        print i
        gb.get_group(i)

The issues is that in _get_index of GroupBy, these lines assume that if there is a tuple in the index, then the index is a multi-index, which in the above test case isn't true. Maybe there is some other way to detect that values are from a multi-index, or should pandas explicitly not support tuples in this situation (in an index of a groupby)

    pandas/core/groupby.py:

    sample = next(iter(self.indices))
    if isinstance(sample, tuple):
        if not isinstance(name, tuple):
            raise ValueError("must supply a tuple to get_group with multiple grouping keys")
        if not len(name) == len(sample):
            raise ValueError("must supply a a same-length tuple to get_group with multiple grouping keys")

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4