Skip to content

to_dense does not preserve dtype in SparseArray #10648

Closed
@ebolyen

Description

@ebolyen

This isn't a huge deal, but it seems a little odd:

In [1]: import pandas as pd

In [2]: a = pd.SparseArray([True, False, False, False, True], fill_value=False, dtype=bool)

In [3]: a
Out[3]: 
[True, False, False, False, True]
Fill: False
IntIndex
Indices: array([0, 4], dtype=int32)

In [4]: a.dtype
Out[4]: dtype('bool')

In [5]: d = a.to_dense()

In [6]: d
Out[6]: array([ 1.,  0.,  0.,  0.,  1.])

In [7]: d.dtype
Out[7]: dtype('float64')

I would have expected d to retain the dtype of bool. I can cast down, but I am still wasting 7 bytes per element in the process.

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