Skip to content

categorical series with null converts ints to float #19214

Closed
@cstjean

Description

@cstjean
In [4]: import pandas as pd, numpy as np

In [5]: sr = pd.Series([1,2, np.nan], dtype="O").astype("category")
   ...: sr
   ...: 
Out[5]: 
0    1.0
1    2.0
2    NaN
dtype: category
Categories (2, int64): [1, 2]

In [6]: sr[0]
Out[6]: 1.0

Shouldn't it keep them as ints? Interestingly, pd.Series(["a", 1,2, np.nan], dtype="O").astype("category") doesn't do the conversion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugCategoricalCategorical Data TypeDtype 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