Skip to content

DEPR: upcasting on invalid fill_value in unstack #53868

@jbrockmendel

Description

@jbrockmendel

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

ser = pd.Series([1, 2, None, 4, 5, None])
ser.index = pd.MultiIndex.from_arrays([range(6), range(6, 12)])

>>> ser.unstack(fill_value="a")
    6    7    8    9    10   11
0  1.0    a    a    a    a    a
1    a  2.0    a    a    a    a
2    a    a  NaN    a    a    a
3    a    a    a  4.0    a    a
4    a    a    a    a  5.0    a
5    a    a    a    a    a  NaN

Issue Description

ATM in unstack (specifically in _Unstacker.get_new_values) we pass a fill_value to maybe_promote which upcasts on fill_values that can't be held normally. We only do this for numpy dtypes, not EADtypes, which is a not-great inconsistency.

In the spirit of PDEP-6, should we consider deprecating this upcasting? Or like in #53802, maybe allow int->float?

Expected Behavior

NA

Installed Versions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeprecateFunctionality to remove in pandasDtype ConversionsUnexpected or buggy dtype conversionsNeeds DiscussionRequires discussion from core team before further actionReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions