Path: blob/main/py-polars/tests/unit/interop/test_arrow_stream_error.py
8407 views
"""Test for https://github.com/pola-rs/polars/issues/25966."""12from __future__ import annotations34from typing import TYPE_CHECKING56import pyarrow as pa7import pytest89import polars as pl10from polars.exceptions import ComputeError1112if TYPE_CHECKING:13from collections.abc import Iterator141516def test_arrow_stream_error_raises_compute_error() -> None:17error_msg = "simulated error"1819def failing_generator() -> Iterator[pa.RecordBatch]:20raise pa.ArrowInvalid(error_msg)21yield2223schema = pa.schema([("col", pa.int64())])24reader = pa.RecordBatchReader.from_batches(schema, failing_generator())2526class FailingStream:27def __arrow_c_stream__(self, requested_schema: object = None) -> object:28return reader.__arrow_c_stream__(requested_schema)2930with pytest.raises(ComputeError, match=error_msg):31pl.from_arrow(FailingStream())323334