diff --git a/openbb_platform/providers/cboe/openbb_cboe/utils/helpers.py b/openbb_platform/providers/cboe/openbb_cboe/utils/helpers.py index f537ce8db68..b439f3d791b 100644 --- a/openbb_platform/providers/cboe/openbb_cboe/utils/helpers.py +++ b/openbb_platform/providers/cboe/openbb_cboe/utils/helpers.py @@ -701,7 +701,7 @@ async def _get_settlement_csv(url: str, **kwargs) -> DataFrame: """ from io import StringIO - from pandas import DataFrame, read_csv + from pandas import DataFrame, read_csv, to_numeric response = await get_cboe_data(url, use_cache=False, **kwargs) data = read_csv(StringIO(response), index_col=None, parse_dates=True) @@ -711,6 +711,9 @@ async def _get_settlement_csv(url: str, **kwargs) -> DataFrame: data.columns = [to_snake_case(c) for c in data.columns] + if "price" in data.columns: + data["price"] = to_numeric(data["price"], errors="coerce") + return data.rename(columns={"expiration_date": "expiration"}) diff --git a/openbb_platform/providers/cboe/tests/test_models.py b/openbb_platform/providers/cboe/tests/test_models.py index 1c426d5df41..4f00ccb1800 100644 --- a/openbb_platform/providers/cboe/tests/test_models.py +++ b/openbb_platform/providers/cboe/tests/test_models.py @@ -1038,6 +1038,24 @@ class TestFuturesSettlements: final_settlement=False, ) + def test_non_numeric_price_is_null(self): + """The options file prints CAB for cabinet trades; that price is null.""" + csv = ( + "Product,Symbol,Expiration Date,Price\n" + "IBYO,IBYO/H7 P16800,2027-03-01,0.7389\n" + "IBYO,IBYO/Z6 P17000,2026-12-01,CAB\n" + ) + query = CboeFuturesSettlementsFetcher.transform_query({"options": True}) + + with patch( + "openbb_cboe.utils.helpers.get_cboe_data", new=AsyncMock(return_value=csv) + ): + raw = asyncio.run(CboeFuturesSettlementsFetcher.aextract_data(query, None)) + + results = CboeFuturesSettlementsFetcher.transform_data(query, raw) + + assert [r.price for r in results] == [0.7389, None] + def test_empty_raises(self): """A session with no published prices raises EmptyDataError.""" query = CboeFuturesSettlementsFetcher.transform_query({})