Skip to content

SparseDataFrame empty slice coerces to loses dtype and fill_value #21993

Closed
@TomAugspurger

Description

@TomAugspurger
import pandas as pd
import numpy as np

In [59]: df = pd.SparseDataFrame({"A": pd.SparseSeries(np.array([1, 1, 0], dtype='uint8'), fill_value=0), "B": pd.SparseSeries(np.array([1, 1, 0], dtype='uint8'), fill_value=0)})

In [60]: df.dtypes
Out[60]:
A    uint8
B    uint8
dtype: object

In [61]: df.A.fill_value
Out[61]: 0

In [62]: df.iloc[0:0].dtypes
Out[62]:
A    float64
B    float64
dtype: object

In [63]: df.iloc[0:0].A.fill_value
Out[63]: nan

non-empty slices are fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Dtype ConversionsUnexpected or buggy dtype conversionsIndexingRelated to indexing on series/frames, not to indexes themselvesSparseSparse Data Type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions