Skip to content

use of iloc with heterogeneous DataFrame coerces dtype? #5256

Closed
@jason-s

Description

@jason-s

I'm using pandas 0.11.0 and numpy 1.7.1 in Anaconda Python 1.6.0.

The iloc method seems to coerce dtype of values in some cases. For example:

x5 = pd.DataFrame(index=['A','B','C'],columns=['foo','bar','baz'])
x5.foo = np.int16([-1,-2,-3])
x5.bar = np.uint16([1,2,3])
x5.baz = np.uint32([100000,200000,300000])
print x5
print x5.dtypes

   foo  bar     baz
A   -1    1  100000
B   -2    2  200000
C   -3    3  300000
foo     int16
bar    uint16
baz    uint32
dtype: object

So far, so good. Now using iloc, it seems to cause type coercion when a single row is selected:

print x5.iloc[1:2]
   foo  bar     baz
B   -2    2  200000

print x5.iloc[1]
foo    4294967294
bar             2
baz        200000
Name: B, dtype: uint32

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions