OpenBB-finance/OpenBB · error · ValueError
Error: expected data with numeric values.
Error message
Error: expected data with numeric values.
What it means
In create_line_chart's auto_layout branch, columns are ordered by their max-min spread computed with numeric_only=True. If no column is numeric, the sorted index is empty and the ValueError 'expected data with numeric values' is raised - the multi-axis layout algorithm needs at least one numeric series to assign to y-axes.
Source
Thrown at openbb_platform/obbject_extensions/charting/openbb_charting/charts/generic_charts.py:150
y2 = y2 if y2 else []
yaxis_num = 1
yaxis = f"y{yaxis_num}"
first_y = y[0] # type: ignore[index]
second_y = None
third_y = None
add_scatter = False
# Attempt to layout the chart automatically with multiple y-axis.
mode = scatter_kwargs.pop("mode", "lines")
hovertemplate = scatter_kwargs.pop("hovertemplate", None)
if auto_layout is True:
# Sort columns by the difference between the max and min values.
# This is to help determine which columns should share the same y-axis.
diff = df.max(numeric_only=True) - df.min(numeric_only=True)
sorted_columns = diff.sort_values(ascending=False).index
if sorted_columns is None or len(sorted_columns) == 0:
raise ValueError("Error: expected data with numeric values.")
df = df[sorted_columns] # type: ignore
for i, col in enumerate(df.columns):
if col in y: # type: ignore[operator]
hovertemplate = (
hovertemplate
if hovertemplate
else f"{df[col].name}: %{{y}}<extra></extra>"
)
share_yaxis = should_share_axis(df, first_y, col, threshold=2.5)
if share_yaxis is True:
add_scatter = True
if share_yaxis is False:
yaxis_num = 2
yaxis = f"y{yaxis_num}"
if second_y is None:
second_y = col
add_scatter = TrueView on GitHub (pinned to 3e071fcc2c)
Solutions
- Coerce columns to numeric: df = df.apply(pd.to_numeric, errors='coerce')
- Pass only the numeric columns: create_line_chart(data=df[['price','volume']])
- Disable auto_layout and specify x/y explicitly
Example fix
# before fig = create_line_chart(data=df, auto_layout=True) # all-object dtypes # after df = df.apply(pd.to_numeric, errors='coerce').dropna(axis=1, how='all') fig = create_line_chart(data=df, auto_layout=True)
Defensive patterns
Strategy: validation
Validate before calling
num = df.select_dtypes('number')
assert not num.empty, 'line chart auto_layout needs numeric columns'
df = df[num.columns.union(df.columns[:1])] Type guard
def has_numeric_columns(df: pd.DataFrame) -> bool:
return not df.select_dtypes('number').empty Try / catch
try:
fig = create_line_chart(data=df, auto_layout=True)
except ValueError as e:
if 'numeric values' in str(e):
fig = create_line_chart(data=df.apply(pd.to_numeric, errors='coerce').dropna(axis=1, how='all'), auto_layout=True) Prevention
- Coerce dtypes with pd.to_numeric at ingest time
- Validate select_dtypes('number') is non-empty before auto_layout
- Avoid object-dtype columns from CSV imports
When it happens
Trigger: Calling create_line_chart(..., auto_layout=True) with a DataFrame whose columns are all strings/dates/objects; mixed frames where numeric columns are stored as object dtype (e.g. strings '1.2'); auto-layout reached through .charting() on results with only categorical fields.
Common situations: Provider data read from CSV with numbers as strings; date-only DataFrames; columns containing None-heavy object arrays that numeric_only drops entirely.
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/60b1639203b1d0e5.
Report an issue: GitHub.