mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-30 05:03:54 +00:00
fix(cboe): a non-numeric settlement price is null (#7759)
The futures options settlement file prints CAB in the price column for cabinet trades. The column then reads as text and the row fails float validation, so the whole options request failed. Settlement prices are coerced to numbers, and a non-numeric price becomes null; the row is kept. Co-authored-by: artcashin <artinnj@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: dlee-bq <dlee@brightquery.com>
This commit is contained in:
@@ -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"})
|
||||
|
||||
|
||||
|
||||
@@ -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({})
|
||||
|
||||
Reference in New Issue
Block a user