diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 6ddb1613076acc..17a0cc31928ba2 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -280,7 +280,7 @@ Numeric Conversion ^^^^^^^^^^ -- +- Raise ValueError in :meth:`PandasColumn._dtype_from_pandasdtype` for currently unhandled dtypes. (:issue:`55332`) - Strings diff --git a/pandas/core/interchange/column.py b/pandas/core/interchange/column.py index acfbc5d9e6c627..6686dd86147716 100644 --- a/pandas/core/interchange/column.py +++ b/pandas/core/interchange/column.py @@ -144,7 +144,12 @@ def _dtype_from_pandasdtype(self, dtype) -> tuple[DtypeKind, int, str, str]: elif isinstance(dtype, DatetimeTZDtype): byteorder = dtype.base.byteorder # type: ignore[union-attr] else: - byteorder = dtype.byteorder + try: + byteorder = dtype.byteorder + except AttributeError: + raise ValueError( + f"Data type {dtype} not supported by interchange protocol" + ) return kind, dtype.itemsize * 8, dtype_to_arrow_c_fmt(dtype), byteorder diff --git a/pandas/tests/interchange/test_impl.py b/pandas/tests/interchange/test_impl.py index 8a25a2c1889f3d..ccb710429ead8f 100644 --- a/pandas/tests/interchange/test_impl.py +++ b/pandas/tests/interchange/test_impl.py @@ -326,3 +326,17 @@ def test_interchange_from_non_pandas_tz_aware(): dtype="datetime64[us, Asia/Kathmandu]", ) tm.assert_frame_equal(expected, result) + + +def test_not_handled() -> None: + pa = pytest.importorskip("pyarrow", "11.0.0") + df = pd.DataFrame( + { + "b": pd.Series([True, False], dtype="boolean"), + } + ) + with pytest.raises( + ValueError, + match="Data type boolean not supported by interchange protocol", + ): + pa.interchange.from_dataframe(df)