Skip to content

groupby casting to int64 #15027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
masongallo opened this issue Dec 31, 2016 · 2 comments
Closed

groupby casting to int64 #15027

masongallo opened this issue Dec 31, 2016 · 2 comments
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Dtype Conversions Unexpected or buggy dtype conversions Groupby

Comments

@masongallo
Copy link
Contributor

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()

INSTALLED VERSIONS ------------------ commit: None python: 2.7.12.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-57-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 27.2.0
Cython: 0.24.1
numpy: 1.11.1
scipy: 0.18.1
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.4.6
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: 1.1.0
tables: 3.2.3.1
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.3
lxml: 3.6.4
bs4: 4.5.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.42.0
pandas_datareader: None

@chris-b1
Copy link
Contributor

chris-b1 commented Jan 1, 2017

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.

dtypes = [('float64', 'float64_t', 'float64_t', 'np.float64'),

Probably not too hard to expand those templates to cover more dtypes.

@chris-b1 chris-b1 added Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Dtype Conversions Unexpected or buggy dtype conversions Groupby labels Jan 1, 2017
@jreback
Copy link
Contributor

jreback commented Jan 1, 2017

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 #14937.

@jreback jreback closed this as completed Jan 1, 2017
@jreback jreback added this to the won't fix milestone Jan 1, 2017
@TomAugspurger TomAugspurger modified the milestones: won't fix, No action Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Dtype Conversions Unexpected or buggy dtype conversions Groupby
Projects
None yet
Development

No branches or pull requests

4 participants