Skip to content

int64 Index in 0.17 typcasts '0' string to integer #11836

Closed
@AlbertDeFusco

Description

@AlbertDeFusco

Here's what I got. Is this expected behavior? I could not find a reference for this functionality in the release notes.

0.16

conda create -n pd pandas=0.16 python=3.4 ipython

In 0.16 the dtype of the index changes to object when adding a row with '0'.

In [1]: import pandas as pd
In [2]: import numpy as np
In [3]: data = np.random.random(10)                                                                                     
In [4]: m=pd.Series(data)
In [5]: m[0]=0.4444
In [6]: m.index
Out[6]: Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype='int64')
In [7]: m['0']=0.5555
In [8]: m.index
Out[8]: Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, '0'], dtype='object')

0.17.1

conda create -n pd pandas=0.17 python=3.4 ipython

In 0.17.1 The index dtype does not change, but typecasts to the integer 0. Repeated assignment at the integer 0 index appends more 0s to the index.

In [1]: import pandas as pd
In [2]: import numpy as np
In [3]: data = np.random.random(10)                                                                                     
In [4]: m=pd.Series(data)
In [5]: m[0]=0.4444
In [6]: m.index
Out[6]: Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype='int64')
In [7]: m['0']=0.5555
In [8]: m.index
Out [8]: Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0], dtype='int64')
In [9]: m['0']=0.6666
In [10]: m.index
Out[10]: Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0], dtype='int64')
In [11]: m[0]
Out[11]: 
0    0.4444
0    0.5555
0    0.6666
dtype: float64

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