forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: add BooleanArray extension array (pandas-dev#29555)
- Loading branch information
1 parent
7d7f885
commit bb904cb
Showing
4 changed files
with
205 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
.. currentmodule:: pandas | ||
|
||
.. _boolean: | ||
|
||
************************** | ||
Nullable Boolean Data Type | ||
************************** | ||
|
||
.. versionadded:: 1.0.0 | ||
|
||
.. _boolean.klean: | ||
|
||
Kleene Logic | ||
------------ | ||
|
||
:class:`arrays.BooleanArray` implements Kleene logic (sometime called three-value logic) for | ||
logical operations like ``&`` (and), ``|`` (or) and ``^`` (exclusive-or). | ||
|
||
Here's a table for ``and``. | ||
|
||
========== =========== ============ | ||
left value right value output value | ||
========== =========== ============ | ||
True True True | ||
True False False | ||
True NA NA | ||
False False False | ||
False NA False | ||
NA NA NA | ||
========== =========== ============ | ||
|
||
|
||
And for ``or`` | ||
|
||
========== =========== ============ | ||
left value right value output value | ||
========== =========== ============ | ||
True True True | ||
True False True | ||
True NA True | ||
False False False | ||
False NA NA | ||
NA NA NA | ||
========== =========== ============ | ||
|
||
And for ``xor`` | ||
|
||
========== =========== ============ | ||
left value right value output value | ||
========== =========== ============ | ||
True True False | ||
True False True | ||
True NA NA | ||
False False False | ||
False NA NA | ||
NA NA NA | ||
========== =========== ============ | ||
|
||
When an ``NA`` is present in an operation, the output value is ``NA`` only if | ||
the result cannot be determined soley based on the other input. For example, | ||
``True | NA`` is ``True``, because both ``True | True`` and ``True | False`` | ||
are ``True``. In that case, we don't actually need to consider the value | ||
of the ``NA``. | ||
|
||
On the other hand, ``True & NA`` is ``NA``. The result depends on whether | ||
the ``NA`` really is ``True`` or ``False``, since ``True & True`` is ``True``, | ||
but ``True & False`` is ``False``, so we can't determine the output. | ||
|
||
|
||
This differs from how ``np.nan`` behaves in logical operations. Pandas treated | ||
``np.nan`` is *always false in the output*. | ||
|
||
In ``or`` | ||
|
||
.. ipython:: python | ||
pd.Series([True, False, np.nan], dtype="object") | True | ||
pd.Series([True, False, np.nan], dtype="boolean") | True | ||
In ``and`` | ||
|
||
pd.Series([True, False, np.nan], dtype="object") & True | ||
pd.Series([True, False, np.nan], dtype="boolean") & True |
This file contains 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
This file contains 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
This file contains 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