Skip to content

BUG: DataFrame Apply unexpectedly casts types (uint64) #9506

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
bdmcfar opened this issue Feb 17, 2015 · 2 comments · Fixed by #53591
Closed

BUG: DataFrame Apply unexpectedly casts types (uint64) #9506

bdmcfar opened this issue Feb 17, 2015 · 2 comments · Fixed by #53591
Labels
Apply Apply, Aggregate, Transform, Map Bug Dtype Conversions Unexpected or buggy dtype conversions good first issue Needs Tests Unit test(s) needed to prevent regressions

Comments

@bdmcfar
Copy link

bdmcfar commented Feb 17, 2015

When using apply on a series, pandas is returning a series of int64 even though the target values were uint64.

import numpy as np
import pandas as pd

uintDF = pd.DataFrame(np.uint64([1,2,3,4,5]),columns=['Numbers'])
indexDF = pd.DataFrame([2,3,2,1,2],columns=['Indices'])

def retrieve(targetRow,targetDF):
    val = targetDF['Numbers'].iloc[targetRow]
    return val

resultDF = indexDF['Indices'].apply(retrieve,args=(uintDF,))
print uintDF.dtypes

Numbers uint64
dtype: object

print resultDF.dtypes

dtype('int64')

I'm aware this specific functionality is possible through iloc(columnVector) but my real retrieve function is more complex.

Thank you.

INSTALLED VERSIONS

commit: None
python: 2.7.5.final.0
python-bits: 64
OS: Linux
OS-release: 3.0.38-0.5-default
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.15.2
nose: 1.2.1
Cython: 0.21.1
numpy: 1.7.1
scipy: 0.12.0
statsmodels: 0.6.1
IPython: 2.3.1
sphinx: 1.1.3
patsy: 0.3.0
dateutil: 2.3
pytz: 2012j
bottleneck: 0.6.0
tables: 3.1.1
numexpr: 2.4
matplotlib: 1.2.0
openpyxl: 1.6.2
xlrd: 0.9.0
xlwt: 0.7.4
xlsxwriter: None
lxml: 3.1.0
bs4: 4.2.1
html5lib: None
httplib2: None
apiclient: None
rpy2: 2.3.3
sqlalchemy: 0.7.8
pymysql: None
psycopg2: None

@jreback
Copy link
Contributor

jreback commented Feb 18, 2015

dealing with uint64 is somewhat tricky; its not well-supported. In any event you should do this:
(this doesn't fix the problem but is a more efficient way of accessing that doesn't involve chain indexing).

In [16]: type(uintDF.ix[0,'Numbers'])
Out[16]: numpy.uint64

In [17]: type(uintDF.ix[2,'Numbers'])
Out[17]: numpy.uint64

@jreback jreback added Bug Dtype Conversions Unexpected or buggy dtype conversions labels Feb 18, 2015
@jreback jreback added this to the 0.17.0 milestone Feb 18, 2015
@jreback jreback changed the title BUG: DataFrame Apply unexpectedly casts types BUG: DataFrame Apply unexpectedly casts types (uint64) Feb 18, 2015
@mroeschke mroeschke added the Apply Apply, Aggregate, Transform, Map label Dec 23, 2019
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
@rhshadrach
Copy link
Member

I now get uint64. I believe this was part of #47475, but it looks like tests for groupby may need to be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Bug Dtype Conversions Unexpected or buggy dtype conversions good first issue Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants