Skip to content

bug in groupby.apply?, goes away if I copy the data. #5545

Closed
@hhuuggoo

Description

@hhuuggoo

Tested pandas 0.11, and 0.12, both exhibit this problem

import pandas as pd

data = pd.DataFrame({'id_field' : [100, 100, 200, 300], 'category' : ['a','b','c','c'], 'value' : [1,2,3,4]})

def filt1(x):
    if x.shape[0] == 1:
        return x.copy()
    else:
        return x[x.category == 'c']


def filt2(x):
    if x.shape[0] == 1:
        return x
    else:
        return x[x.category == 'c']

#works fine                                                                                                                                                                                                                                    
print data.groupby('id_field').apply(filt1)

#throws error                                                                                                                                                                                                                                  
print data.groupby('id_field').apply(filt2)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions