df = pd.DataFrame(
    {'ts':[1,2,3,4,60,61,62,63,64,150,155,156,
           1,2,3,4,60,61,62,63,64,150,155,156,
           1,2,3,4,60,61,62,63,64,150,155,156],
    'id': [1,2,3,4,60,61,62,63,64,150,155,156,
           71,72,73,74,80,81,82,83,64,160,165,166,
           21,22,23,24,90,91,92,93,94,180,185,186],
    'other':['x','x','x','x','x','x','x','x','x','x','x','x',
             'y','y','y','y','y','y','y','y','y','y','y','y',
             'z','z','z','z','z','z','z','z','z','z','z','z'],
    'user':['x','x','x','x','y','x','x','x','x','x','x','x',
            'y','y','y','y','x','y','y','y','y','y','y','y',
            'z','z','z','z','z','z','z','z','z','z','z','z']
    })
df.set_index('id', inplace=True)
df.sort_values('ts',inplace=True)
for x, g in df.groupby('user'):
    # call 1
    print(g.ts.diff())
# call 2
df.groupby('user').ts.diff()
I'm not sure why I'm getting an error in call 2. Also I noticed that when I remove the sort_values the call 2 passes.
Can somebody please explain this behavior?