Skip to content

BUG: SparseArray.map allows the fill value to be included in the sparse values #52095

Closed
@topper-123

Description

@topper-123

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

>>> import pandas as pd
>>> sp = pd.arrays.SparseArray([1, np.nan])
>>> mapped = sp.map(lambda x: np.nan)
>>> pd.isna(mapped.fill_value)
True
>>> pd.isna(mapped.sp_values)[0]
True

Issue Description

The current implementation of SparseArray.map allows the fill value to be included in the sparse values, causing potential problems.

Expected Behavior

SparseArray.map It should raise or recalculate the sparse array.

Installed Versions

Replace this line with the output of pd.show_versions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions