groupby - apply applies to the first group twice · Issue #7739 · pandas-dev/pandas (original) (raw)

This bug is easy to reproduce:

def printA(group):
    print group.A.values[0]
    return 0
pandas.DataFrame({'A': [0,0,1,1], 'B': [0,1,0,1]}).groupby('A').apply(printA)

This should print

and return a Series containing two zeroes. Although it does return the expected Series, it prints

So, the function printA is being applied to the first group twice. This doesn't seem to affect the eventual returned result of apply, but it duplicates any side effects, and if printA performed some expensive computation, it would increased the time to completion.