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..45a7d5a478bb7b 100644 --- a/pandas/core/interchange/column.py +++ b/pandas/core/interchange/column.py @@ -134,6 +134,7 @@ def _dtype_from_pandasdtype(self, dtype) -> tuple[DtypeKind, int, str, str]: # Note: 'c' (complex) not handled yet (not in array spec v1). # 'b', 'B' (bytes), 'S', 'a', (old-style string) 'V' (void) not handled # datetime and timedelta both map to datetime (is timedelta handled?) + not_handled = ["b", "B", "S", "a", "V"] kind = _NP_KINDS.get(dtype.kind, None) if kind is None: @@ -143,6 +144,8 @@ def _dtype_from_pandasdtype(self, dtype) -> tuple[DtypeKind, int, str, str]: byteorder = dtype.numpy_dtype.byteorder elif isinstance(dtype, DatetimeTZDtype): byteorder = dtype.base.byteorder # type: ignore[union-attr] + elif dtype.kind in not_handled: + raise ValueError(f"Data type {dtype} not supported by interchange protocol") else: byteorder = dtype.byteorder