Skip to content

more descriptive error message when assigning dataframe with different index shape to column #4107

Closed
@hayd

Description

@hayd

http://stackoverflow.com/questions/17432944/python-pandas-error-when-doing-groupby-counts

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Error ReportingIncorrect or improved errors from pandas

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions