Skip to content

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

@bdmcfar

Description

@bdmcfar

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApplyApply, Aggregate, Transform, MapBugDtype ConversionsUnexpected or buggy dtype conversionsNeeds TestsUnit test(s) needed to prevent regressionsgood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions