Repository navigation
ENH: astype("boolean") converts values as astype(bool) (GH#37614) - #71770
Merged
Merged
Conversation
Values other than booleans, 0 and 1 are now converted the same way as astype(bool) instead of raising, with missing values becoming NA. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
…mies Use take_nd so a missing code with no categories no longer raises IndexError, and check from_dummies input with isin([0, 1]) rather than comparing against the boolean result, which is all-False for pyarrow integer dtypes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jbrockmendel
marked this pull request as ready for review
October 30, 2026 17:24
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # pandas/core/arrays/masked.py # pandas/tests/series/methods/test_map.py
Member
Author
|
We discussed this on the last dev call and agreed on this behavior. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #37614
closes #40566
As decided on the dev call:
BooleanArray._from_sequence, and thereforepd.array(..., dtype="boolean")andastype("boolean"), now converts values the same way asastype(bool)instead of raising for anything other than booleans, 0 and 1. Missing values (NA, None, NaT) becomeNA. NaN also becomesNA, except underfuture.distinguish_nan_and_na, where it converts toTrueasbool(np.nan)does.astype(bool). Categoricals convert each category once.from_dummieschecks that its input contains only 0s and 1s._cast_pointwise_resultchecks whether an all-missing result is valid NA for the dtype (BUG: setitem-with-expansion, map and groupby.agg raised for a value the dtype cannot hold #70233).AI disclosure: drafted with Claude Code (
claude opus 5.5 (high)), which implemented the change and tests under my direction.