Skip to content

Commit 1ddba4a

Browse files
MarcoGorellipmhatre1
authored andcommitted
BUG: DataFrame Interchange Protocol errors on Boolean columns (pandas-dev#57758)
* BUG: DataFrame Interchange Protocol errors on Boolean columns [skip-ci] * whatsnew
1 parent ee07fa8 commit 1ddba4a

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
@@ -459,6 +459,7 @@ def test_non_str_names_w_duplicates():
459459
),
460460
([1.0, 2.25, None], "Float32", "float32"),
461461
([1.0, 2.25, None], "Float32[pyarrow]", "float32"),
462+
([True, False, None], "boolean", "bool"),
462463
([True, False, None], "boolean[pyarrow]", "bool"),
463464
(["much ado", "about", None], "string[pyarrow_numpy]", "large_string"),
464465
(["much ado", "about", None], "string[pyarrow]", "large_string"),
@@ -521,6 +522,7 @@ def test_pandas_nullable_with_missing_values(
521522
),
522523
([1.0, 2.25, 5.0], "Float32", "float32"),
523524
([1.0, 2.25, 5.0], "Float32[pyarrow]", "float32"),
525+
([True, False, False], "boolean", "bool"),
524526
([True, False, False], "boolean[pyarrow]", "bool"),
525527
(["much ado", "about", "nothing"], "string[pyarrow_numpy]", "large_string"),
526528
(["much ado", "about", "nothing"], "string[pyarrow]", "large_string"),

0 commit comments

Comments
 (0)