Skip to content

BUG: SparseDataFrame construction with lists not coercing to dtype #15682

Closed
@jreback

Description

@jreback

coercion happens

In [12]: df = pd.SparseDataFrame({'a': [1, 0, 0],
    ...:                          'b': [0, 1, 0],
    ...:                          'c': [0, 0, 1]}, dtype='uint8', default_fill_value=0)

In [13]: df.dtypes
Out[13]: 
a    int64
b    int64
c    int64
dtype: object

respected here

In [23]: df = pd.SparseDataFrame({'a': pd.SparseSeries([1, 0, 0], dtype='uint8'),
    ...:                          'b': pd.SparseSeries([0, 1, 0], dtype='uint8'),
    ...:                          'c': pd.SparseSeries([0, 0, 1], dtype='uint8')}, default_fill_value=0)

In [24]: df.dtypes
Out[24]: 
a    uint8
b    uint8
c    uint8
dtype: object

In [25]: df.default_fill_value
Out[25]: 0

And here

In [15]: df = pd.DataFrame({'a': [1, 0, 0],
    ...:                          'b': [0, 1, 0],
    ...:                          'c': [0, 0, 1]}, dtype='uint8').to_sparse(fill_value=0)

In [17]: df.dtypes
Out[17]: 
a    uint8
b    uint8
c    uint8
dtype: object

In [18]: df.default_fill_value
Out[18]: 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsSparseSparse Data Type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions