Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jorisvandenbossche opened this issue Aug 21, 2023 · 2 comments · Fixed by #54527
Closed
Labels
API Design Blocker Blocking issue or pull request for an upcoming release Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Aug 21, 2023

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.

@jorisvandenbossche jorisvandenbossche added Indexing Related to indexing on series/frames, not to indexes themselves API Design Blocker Blocking issue or pull request for an upcoming release labels Aug 21, 2023
@jorisvandenbossche jorisvandenbossche added this to the 2.1 milestone Aug 21, 2023
@MarcoGorelli
Copy link
Member

hey @jorisvandenbossche, thanks for opening the issue - want to push your helper function to the branch of that PR, and then I'll take it forwards?

@jorisvandenbossche
Copy link
Member Author

FWIW all occurrences of the setitem deprecation warning that I saw in the downstream pyarrow and geopandas CI builds testing with pandas nightly, were (based on a quick look) all cases like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Blocker Blocking issue or pull request for an upcoming release Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants