Skip to content

Commit dd56eff

Browse files
committed
BUG: DataFrame Interchange Protocol errors on Boolean columns [skip-ci]
1 parent c5c108e commit dd56eff

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

doc/source/whatsnew/v2.2.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Bug fixes
2424
~~~~~~~~~
2525
- :meth:`DataFrame.__dataframe__` was showing bytemask instead of bitmask for ``'string[pyarrow]'`` validity buffer (:issue:`57762`)
2626
- :meth:`DataFrame.__dataframe__` was showing non-null validity buffer (instead of ``None``) ``'string[pyarrow]'`` without missing values (:issue:`57761`)
27+
- :meth:`DataFrame.__dataframe__` was producing incorrect data buffers when the column's type was nullable boolean (:issue:`55332`)
2728

2829
.. ---------------------------------------------------------------------------
2930
.. _whatsnew_222.other:

pandas/core/interchange/utils.py

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
DatetimeTZDtype,
1717
)
1818

19+
from pandas import BooleanDtype
20+
1921
if typing.TYPE_CHECKING:
2022
from pandas._typing import DtypeObj
2123

@@ -142,6 +144,9 @@ def dtype_to_arrow_c_fmt(dtype: DtypeObj) -> str:
142144
elif isinstance(dtype, DatetimeTZDtype):
143145
return ArrowCTypes.TIMESTAMP.format(resolution=dtype.unit[0], tz=dtype.tz)
144146

147+
elif isinstance(dtype, BooleanDtype):
148+
return ArrowCTypes.BOOL
149+
145150
raise NotImplementedError(
146151
f"Conversion of {dtype} to Arrow C format string is not implemented."
147152
)

pandas/tests/interchange/test_impl.py

+1
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ def test_non_str_names_w_duplicates():
438438
),
439439
([1.0, 2.25, None], "Float32", "float32"),
440440
([1.0, 2.25, None], "Float32[pyarrow]", "float32"),
441+
([True, False, None], "boolean", "bool"),
441442
([True, False, None], "boolean[pyarrow]", "bool"),
442443
(["much ado", "about", None], "string[pyarrow_numpy]", "large_string"),
443444
(["much ado", "about", None], "string[pyarrow]", "large_string"),

0 commit comments

Comments
 (0)