Skip to content

Commit f848f10

Browse files
MarcoGorellimeeseeksmachine
authored andcommitted
Backport PR pandas-dev#57758: BUG: DataFrame Interchange Protocol errors on Boolean columns
1 parent 7e8d492 commit f848f10

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

doc/source/whatsnew/v2.2.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Fixed regressions
2222

2323
Bug fixes
2424
~~~~~~~~~
25+
- :meth:`DataFrame.__dataframe__` was producing incorrect data buffers when the column's type was nullable boolean (:issue:`55332`)
2526
- :meth:`DataFrame.__dataframe__` was showing bytemask instead of bitmask for ``'string[pyarrow]'`` validity buffer (:issue:`57762`)
2627
- :meth:`DataFrame.__dataframe__` was showing non-null validity buffer (instead of ``None``) ``'string[pyarrow]'`` without missing values (:issue:`57761`)
2728

pandas/core/interchange/utils.py

+3
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ def dtype_to_arrow_c_fmt(dtype: DtypeObj) -> str:
144144
elif isinstance(dtype, DatetimeTZDtype):
145145
return ArrowCTypes.TIMESTAMP.format(resolution=dtype.unit[0], tz=dtype.tz)
146146

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

pandas/tests/interchange/test_impl.py

+2
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ def test_non_str_names_w_duplicates():
470470
),
471471
([1.0, 2.25, None], "Float32", "float32"),
472472
([1.0, 2.25, None], "Float32[pyarrow]", "float32"),
473+
([True, False, None], "boolean", "bool"),
473474
([True, False, None], "boolean[pyarrow]", "bool"),
474475
(["much ado", "about", None], "string[pyarrow_numpy]", "large_string"),
475476
(["much ado", "about", None], "string[pyarrow]", "large_string"),
@@ -532,6 +533,7 @@ def test_pandas_nullable_with_missing_values(
532533
),
533534
([1.0, 2.25, 5.0], "Float32", "float32"),
534535
([1.0, 2.25, 5.0], "Float32[pyarrow]", "float32"),
536+
([True, False, False], "boolean", "bool"),
535537
([True, False, False], "boolean[pyarrow]", "bool"),
536538
(["much ado", "about", "nothing"], "string[pyarrow_numpy]", "large_string"),
537539
(["much ado", "about", "nothing"], "string[pyarrow]", "large_string"),

0 commit comments

Comments
 (0)