Code Sample, a copy-pastable example if possible
from StringIO import StringIO
import pandas as pd
import numpy as np
data = "some_id,other_id,some_int\n1,234,0\n2,324,1"
dtypes = {'some_id': np.uint32, 'other_id': np.uint32, 'some_int': np.int8}
train = pd.read_csv(StringIO(data), dtype=dtypes)
print(train.dtypes) # dtypes is respected
grouped = train.groupby('some_id').some_int.agg(['sum'])
print(grouped.index.dtype) # dtype('int64')
Problem description
I am explicitly asking for uint32 but pandas coerces "some_id" column to int64 after using groupby. Is this intended? Possible duplicate of #14423 ?
Output of pd.show_versions()
Comment From: chris-b1
Though similar in symptom, I don't think this is a dupe of #14423. The root issue here is that the cythonized group sum algo is only defined for a subset of types. https://github.com/pandas-dev/pandas/blob/366241386282272328333256b6e267a68f8133a4/pandas/src/algos_groupby_helper.pxi.in#L18
Probably not too hard to expand those templates to cover more dtypes.
Comment From: jreback
actually this is not supported at all. The index something you are grouping will always be casted. The values are the correct dtypes.
IOW we don't support an integer index except Int64Index. Though soon will have Uint64Index from https://github.com/pandas-dev/pandas/pull/14937.