Skip to content

BUG: indexers coerce partial assignment of float->int #10280

Closed
@jreback

Description

@jreback

xref #10264

converts int -> floats for the entire block.

In [1]: x = pd.DataFrame(data=np.zeros((5,5),dtype=np.int),columns=['a','b','c','d','e'], index=['one','two','three','four','five'])

In [3]: x.loc['three','e'] = 3.1

In [4]: x
Out[4]: 
       a  b  c  d    e
one    0  0  0  0  0.0
two    0  0  0  0  0.0
three  0  0  0  0  3.1
four   0  0  0  0  0.0
five   0  0  0  0  0.0

In [5]: x.dtypes
Out[5]: 
a    float64
b    float64
c    float64
d    float64
e    float64
dtype: object

ok for other kinds of assignments

In [6]: x = pd.DataFrame(data=np.zeros((5,5),dtype=np.int),columns=['a','b','c','d','e'], index=['one','two','three','four','five'])

 [8]: x.loc['three','e'] = 'foo'

In [9]: x
Out[9]: 
       a  b  c  d    e
one    0  0  0  0    0
two    0  0  0  0    0
three  0  0  0  0  foo
four   0  0  0  0    0
five   0  0  0  0    0

In [10]: x.dtypes
Out[10]: 
a     int64
b     int64
c     int64
d     int64
e    object
dtype: object

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions