OpenBB-finance/OpenBB · error · OpenBBError
Invalid data format. Expected a list of ImfMaritimeChokePoin
Error message
Invalid data format. Expected a list of ImfMaritimeChokePointInfoData.
What it means
Type guard in the maritime chokepoint chart view: the data argument must be a list whose items are all ImfMaritimeChokePointInfoData. Because of Python operator precedence, the condition is effectively (data is not None and not isinstance(data, list)) or (not all(isinstance(item, ...) for item in data)) - so a non-list iterable or any non-conforming item triggers it. Note it does not guard against data=None, which instead fails later at len().
Source
Thrown at openbb_platform/providers/imf/openbb_imf/views/maritime_chokepoint_info.py:30
from openbb_core.app.model.abstract.error import OpenBBError
from pandas import DataFrame
try:
from openbb_charting.core.openbb_figure import OpenBBFigure
from plotly import graph_objects as go
from plotly.subplots import make_subplots
except Exception as e:
raise OpenBBError(
"Could not import Charting modules. Install with `pip install openbb-charting`."
+ f" -> {e}"
) from e
if (
data is not None
and not isinstance(data, list)
or not all(isinstance(item, ImfMaritimeChokePointInfoData) for item in data)
):
raise OpenBBError(
"Invalid data format. Expected a list of ImfMaritimeChokePointInfoData."
)
if len(data) == 0:
raise OpenBBError("No data to plot.")
df = DataFrame([item.model_dump() for item in data])
if theme == "dark":
geo_bgcolor = "rgba(0,0,0,0)"
landcolor = "#3a5d3a"
countrycolor = "#cccccc"
oceancolor = "#223355"
coastlinecolor = "#cccccc"
lakecolor = "#0d47a1"
rivercolor = "#0d47a1"
table_header_fill = "#222e3c"
table_header_font = "#fff"
table_cell_fill = ["#232323", "#181818"] * (len(df) // 2 + 1)
font_color = "#fff"View on GitHub (pinned to 3e071fcc2c)
Solutions
- Pass the fetcher/endpoint's return value (list of ImfMaritimeChokePointInfoData) directly to the view without re-serializing.
- If you have dicts, convert first: [ImfMaritimeChokePointInfoData.model_validate(d) for d in rows].
- Guard against None before calling (the built-in check doesn't reject it).
- Avoid mixing items from different provider models in one call.
Example fix
# before
plot_maritime_chokepoint_info([{'date': '...', 'chokepoint': 'Suez', ...}])
# after
from openbb_imf.models.maritime_chokepoint_info import ImfMaritimeChokePointInfoData
data = [ImfMaritimeChokePointInfoData.model_validate(d) for d in rows]
plot_maritime_chokepoint_info(data) Defensive patterns
Strategy: type-guard
Validate before calling
from openbb_imf.models.maritime_chokepoint_info import ImfMaritimeChokePointInfoData
def is_chokepoint_data_list(data) -> bool:
return isinstance(data, list) and len(data) > 0 and all(
isinstance(i, ImfMaritimeChokePointInfoData) for i in data
)
assert is_chokepoint_data_list(data), 'pass model instances, not dicts' Type guard
from openbb_imf.models.maritime_chokepoint_info import ImfMaritimeChokePointInfoData
def is_chokepoint_data_list(data: object) -> bool:
return isinstance(data, list) and len(data) > 0 and all(
isinstance(i, ImfMaritimeChokePointInfoData) for i in data
) Try / catch
from openbb_core.app.model.abstract.error import OpenBBError
try:
plot_maritime_chokepoint_info(data)
except OpenBBError as e:
if 'Invalid data format' in str(e):
data = [ImfMaritimeChokePointInfoData.model_validate(d) for d in data]
plot_maritime_chokepoint_info(data)
else:
raise Prevention
- Never re-serialize fetcher results to dicts before charting
- Keep None out - the built-in guard doesn't reject it
- Validate list homogeneity before calling chart views
When it happens
Trigger: Passing a DataFrame, a generator, a list of dicts, or a mixed list (e.g. result rows appended with raw dicts) into plot_maritime_chokepoint_info instead of validated model instances; also passing None (falls through the guard, then crashes on len(data)).
Common situations: Custom pipelines that re-serialize fetcher output to dicts before plotting; combining results from multiple providers where item types differ; test code passing mocks that aren't ImfMaritimeChokePointInfoData instances.
Related errors
- Invalid data format. Expected a list of ImfPortInfoData.
- No data to plot.
- No data to plot.
- This charting method does not support {provider}. Supported
- Unable to import the required module.
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/4db81816d72e8a04.
Report an issue: GitHub.