Skip to content

API/DEPR: disallow casting nan-float to bool #62687

@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([np.nan])

>>> ser.astype(bool)
0    True

This is correct inasmuch as bool(np.nan) is True, but I think it's a bit surprising. Analogous to how we deprecated and later disallowed .astype("int64") when NaNs are present, should we deprecate allowing this for bool?

xref #43018

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions