Skip to content

PDEP-6: special case (allow) upcasting to float when setting NaN in integer series #54660

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

Currently, on the main branch with the PDEP-6 (no-casting in setitem) warnings, we get:

>>> ser[0] = np.nan
FutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas.
Value 'nan' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.

Given that this is a bit a special cast (with numpy integers not supporting missing values, so we make this upcast in other places like reindexing as well), and in a possible future with nullable integers by default, the above would again be allowed (and then preserve the dtype), we could decide to special case specifically setting NaN into an integer Series for now, and still allow the upcast in this specific case.

@MarcoGorelli opening this issue to keep track of what we discussed. You already started on a fix (#54527?), and I also started working on a short-circuiting helper function to determine if we have an array of only-NaNs-or-integers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignBlockerBlocking issue or pull request for an upcoming releaseIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions