-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
BUG: handle None in dtype=bool Series with Kleene 3-valued logic (#62370) #62371
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
Conversation
…e for logical operations
the dosctring check required me to return a true or false bool only
…manual pre-commit hooks (pull_request)Failing after 16m
…or truthy values like 1
Is this AI? We don’t use Kleenex logic except in opt-in dtypes. |
Yes i did use AI to make my work easier and more efficient. Though i have tested it on my end. |
Please don't. They are incredibly verbose and in general low quality. It creates more work for the maintainers.
If you find somewhere in the docs that suggests otherwise, we can change that. |
The default, numpy bool dtype, intentionally doesn't not use Kleene logic and that probably won't change so closing. |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.What does this PR fix?
This pull request updates pandas' logical operations to use Kleene’s three-valued logic (handling
True
,False
, andNA
) for boolean arrays, ensuring that missing values (None
,np.nan
,pd.NA
) propagate correctly in logical operations.Previously,
None
inside adtype=bool
Series was coerced incorrectly, producing results inconsistent with three-valued logic. With this PR, logical operators now follow Kleene semantics consistently.Core logic changes
pandas/core/ops/array_ops.py
:alignOutputWithKleene
— aligns logical operation results with Kleene semantics.is_nullable_bool
— detects nullable boolean operands.safe_is_true
— ensures truthiness checks handle NA values safely.logical_op
inarray_ops.py
to use Kleene logic for elementwise operations when operands are nullable booleans.Test updates
pandas/tests/frame/test_logical_ops.py
pandas/tests/series/test_logical_ops.py
and
,or
, andxor
operations.None
,np.nan
,pd.NA
)These changes ensure pandas’ logical operations with nullable booleans now conform to standard three-valued logic, improving correctness and consistency when handling missing data.