Skip to content

ENH: astype("boolean") converts values as astype(bool) (GH#37614) - #71770

Merged
jbrockmendel merged 5 commits into
pandas-dev:mainfrom
jbrockmendel:enh-boolean
Nov 7, 2026
Merged

jbrockmendel merged 5 commits into
pandas-dev:mainfrom
jbrockmendel:enh-boolean

Conversation

@jbrockmendel

Copy link
Copy Markdown
Member

closes #37614
closes #40566

As decided on the dev call: BooleanArray._from_sequence, and therefore pd.array(..., dtype="boolean") and astype("boolean"), now converts values the same way as astype(bool) instead of raising for anything other than booleans, 0 and 1. Missing values (NA, None, NaT) become NA. NaN also becomes NA, except under future.distinguish_nan_and_na, where it converts to True as bool(np.nan) does.

AI disclosure: drafted with Claude Code (claude opus 5.5 (high)), which implemented the change and tests under my direction.

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>
@jbrockmendel jbrockmendel added Enhancement NA - MaskedArrays Related to pd.NA and nullable extension arrays Astype labels Oct 29, 2026
jbrockmendel and others added 3 commits October 29, 2026 13:57
…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
jbrockmendel marked this pull request as ready for review October 30, 2026 17:24
@jbrockmendel jbrockmendel added this to the 3.2 milestone Nov 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	pandas/core/arrays/masked.py
#	pandas/tests/series/methods/test_map.py
@jbrockmendel

Copy link
Copy Markdown
Member Author

We discussed this on the last dev call and agreed on this behavior.

@jbrockmendel
jbrockmendel merged commit 8ef18ca into pandas-dev:main Nov 7, 2026
55 checks passed
@jbrockmendel
jbrockmendel deleted the enh-boolean branch November 7, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Astype Enhancement NA - MaskedArrays Related to pd.NA and nullable extension arrays

Projects

None yet

1 participant