Skip to content

Conversation

@mzarnecki
Copy link

Related to #62687

This PR adds a FutureWarning when using astype() to convert data containing NaN values to bool dtype. In pandas 3.0, this will raise a ValueError instead.

Changes:

  • Added warning in _astype_nansafe() that triggers when converting to np.bool_ with NaN present
  • Added test test_astype_bool_with_nan_warning() to verify the warning behavior
  • Updated doc/source/whatsnew/v2.3.4.rst

Example:

ser = pd.Series([1.0, 2.0, np.nan])
ser.astype(bool)  # FutureWarning: Converting a Series with NaN values to bool...

@mzarnecki mzarnecki marked this pull request as draft January 7, 2026 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant