Skip to content

Commit fa80ade

Browse files
committed
Raises a ValueError in PandasColumn._dtype_from_pandasdtype for the following unhandled dtypes: 'b', 'B', 'S', 'a', 'V'.
1 parent c8e7a98 commit fa80ade

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

doc/source/whatsnew/v2.2.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ Numeric
280280

281281
Conversion
282282
^^^^^^^^^^
283-
-
283+
- Raise ValueError in :meth:`PandasColumn._dtype_from_pandasdtype` for currently unhandled dtypes. (:issue:`55332`)
284284
-
285285

286286
Strings

pandas/core/interchange/column.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,12 @@ def _dtype_from_pandasdtype(self, dtype) -> tuple[DtypeKind, int, str, str]:
144144
elif isinstance(dtype, DatetimeTZDtype):
145145
byteorder = dtype.base.byteorder # type: ignore[union-attr]
146146
else:
147-
byteorder = dtype.byteorder
147+
try:
148+
byteorder = dtype.byteorder
149+
except AttributeError:
150+
raise ValueError(
151+
f"Data type {dtype} not supported by interchange protocol"
152+
)
148153

149154
return kind, dtype.itemsize * 8, dtype_to_arrow_c_fmt(dtype), byteorder
150155

pandas/tests/interchange/test_impl.py

+14
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,17 @@ def test_interchange_from_non_pandas_tz_aware():
326326
dtype="datetime64[us, Asia/Kathmandu]",
327327
)
328328
tm.assert_frame_equal(expected, result)
329+
330+
331+
def test_not_handled() -> None:
332+
pa = pytest.importorskip("pyarrow", "11.0.0")
333+
df = pd.DataFrame(
334+
{
335+
"b": pd.Series([True, False], dtype="boolean"),
336+
}
337+
)
338+
with pytest.raises(
339+
ValueError,
340+
match="Data type boolean not supported by interchange protocol",
341+
):
342+
pa.interchange.from_dataframe(df)

0 commit comments

Comments
 (0)