more descriptive error message when assigning dataframe with different index shape to column · Issue #4107 · pandas-dev/pandas (original) (raw)
The below example doesn't make sense, but perhaps the error message could be clearer...
df = pd.DataFrame(np.random.randint(0,2,(4,4)),
columns=['a', 'b', 'c', 'd'])
In [11]: df
Out[11]:
a b c d gr
0 0 1 1 0 1
1 1 1 1 0 1
2 0 1 1 0 1
3 1 1 0 1 0
In [12]: df.groupby(['b', 'c']).count()
Out[12]:
a b c d gr
b c
1 0 1 1 1 1 1
1 3 3 3 3 3
df['gr'] = df.groupby(['b', 'c']).count()
---------------------------------------------------------------------------
ValueError: Buffer dtype mismatch, expected 'Python object' but got 'long'