OpenBB-finance/OpenBB · error · ValueError
Error: {e}
Error message
Error: {e} What it means
In the bar chart builder (generic_charts.py), the incoming values are packed into a pandas Series indexed by keys; if that construction fails - length mismatch between keys and values, unhashable/NaN keys, or non-iterable input - the exception is wrapped as ValueError('Error: {e}') with the original message preserved.
Source
Thrown at openbb_platform/obbject_extensions/charting/openbb_charting/charts/generic_charts.py:572
except Exception as _:
figure = OpenBBFigure(create_backend=True)
figure = figure.create_subplots(
1,
1,
shared_xaxes=False,
vertical_spacing=0.06,
horizontal_spacing=0.01,
row_width=[1],
specs=[[{"secondary_y": True}]],
)
try:
data = Series(data=values, index=keys)
increasing_data = data[data > 0] # type: ignore
decreasing_data = data[data < 0] # type: ignore
except Exception as e:
raise ValueError(f"Error: {e}") from e
if not increasing_data.empty: # type: ignore
figure.add_bar(
x=increasing_data.index if orientation == "v" else increasing_data, # type: ignore
y=increasing_data if orientation == "v" else increasing_data.index, # type: ignore
marker=dict(color=colors[0]),
orientation=orientation,
showlegend=False,
width=0.95 / len(keys) * 0.75 if barmode == "group" else 0.95,
hoverinfo="y" if orientation == "v" else "x",
)
if not decreasing_data.empty: # type: ignore
figure.add_bar(
x=decreasing_data.index if orientation == "v" else decreasing_data, # type: ignore
y=decreasing_data if orientation == "v" else decreasing_data.index, # type: ignore
marker=dict(color=colors[1]),
orientation=orientation,
showlegend=False,View on GitHub (pinned to 3e071fcc2c)
Solutions
- Verify lengths match: assert len(keys) == len(values)
- Sanitize keys (drop NaN, convert to str) and values (coerce to float) before calling
- Read the embedded message after 'Error:' - it is pandas' own Series construction error telling you the exact mismatch
Example fix
# before fig = create_bar_chart(values=[1, 2, 3], keys=['a', 'b']) # after assert len(keys) == len(values) fig = create_bar_chart(values=values, keys=keys)
Defensive patterns
Strategy: validation
Validate before calling
assert len(keys) == len(values), f'keys/values length mismatch: {len(keys)} vs {len(values)}'
keys = [str(k) for k in keys]
values = [float(v) for v in values] Type guard
def is_paired_series(keys, values) -> bool:
try:
return len(keys) == len(values) and all(isinstance(k, (str, int, float)) for k in keys)
except TypeError:
return False Try / catch
try:
fig = create_bar_chart(values=values, keys=keys)
except ValueError as e:
if str(e).startswith('Error:'):
logging.error('bar chart data invalid: %s', str(e)) Prevention
- Always assert equal lengths for keys and values
- Stringify keys to avoid NaN/unhashable index errors
- Coerce values to float before charting
When it happens
Trigger: Calling the bar chart function with len(keys) != len(values); keys containing NaN or unhashable types; values as a scalar instead of a sequence; dicts/iterables of inconsistent length.
Common situations: Building category charts from aggregated provider data where a filter dropped some rows but keys were computed beforehand; passing zip results of unequal lists; None values sneaking into keys.
Related errors
- Error: No data to plot.
- Expiration field not found in the data.
- Price field not found in the data.
- Error: Rate column not found in the data.
- Error: Date column not found in the data.
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/703168e88c43a083.
Report an issue: GitHub.