OpenBB-finance/OpenBB · error · ValueError
All columns must be numeric
Error message
All columns must be numeric
What it means
Thrown by the OLS regression endpoint in openbb_econometrics when the selected x_columns/y_column cannot be cast to float via DataFrame.astype(float). statsmodels OLS requires fully numeric design and response matrices, so any non-numeric (string, categorical, date) or NaN-adjacent content in the chosen columns triggers this ValueError, chained from the original pandas cast error.
Source
Thrown at openbb_platform/extensions/econometrics/openbb_econometrics/econometrics_router.py:256
OBBject with the results being summary object.
"""
# pylint: disable=import-outside-toplevel
import re # noqa
import statsmodels.api as sm # noqa
from openbb_core.app.utils import (
basemodel_to_df,
get_target_column,
get_target_columns,
)
X = sm.add_constant(get_target_columns(basemodel_to_df(data), x_columns))
y = get_target_column(basemodel_to_df(data), y_column)
try:
X = X.astype(float)
y = y.astype(float)
except ValueError as exc:
raise ValueError("All columns must be numeric") from exc
results = sm.OLS(y, X).fit()
results_summary = results.summary()
results = {}
for item in results_summary.tables[0].data:
results[item[0].strip()] = item[1].strip()
results[item[2].strip()] = str(item[3]).strip()
table_1 = results_summary.tables[1]
headers = table_1.data[0] # Assuming the headers are in the first row
for i, row in enumerate(table_1.data):
if i == 0: # Skipping the header row
continue
for j, cell in enumerate(row):
if j == 0: # Skipping the row index
continue
key = f"{row[0].strip()}_{headers[j].strip()}" # Combining row index and column headerView on GitHub (pinned to 3e071fcc2c)
Solutions
- Verify dtypes before the call: df.dtypes — only pass float/int columns in x_columns and y_column.
- Coerce the source data: df[c] = pd.to_numeric(df[c], errors='coerce') and dropna() before running the regression.
- Double-check the column names in x_columns/y_column against the actual dataset columns (get_target_column also fails loudly on missing names).
- If a categorical regressor is intended, encode it (dummies) first.
Example fix
# before res = obb.econometrics.ols(data, y_column='revenue', x_columns=['sector', 'growth']) # sector is a string # after df = data.to_df() X = pd.get_dummies(df[['sector']], drop_first=True) df = pd.concat([df[['revenue', 'growth']].apply(pd.to_numeric, errors='coerce'), X], axis=1).dropna() res = obb.econometrics.ols(Data(data=df), y_column='revenue', x_columns=['growth', 'sector_technology'])
Defensive patterns
Strategy: validation
Validate before calling
df = data.to_df()
cols = [y_column] + list(x_columns)
assert all(c in df.columns for c in cols), 'missing column(s)'
non_numeric = [c for c in cols if not pd.api.types.is_numeric_dtype(df[c])]
assert not non_numeric, f'non-numeric columns: {non_numeric}'
df = df[cols].apply(pd.to_numeric, errors='coerce').dropna() Type guard
def columns_are_numeric(df, columns: list[str]) -> bool:
"""True when every named column exists and has a numeric dtype."""
return all(c in df.columns and pd.api.types.is_numeric_dtype(df[c]) for c in columns) Try / catch
try:
res = obb.econometrics.ols(data, y_column=y, x_columns=xs)
except ValueError as e:
if str(e) == 'All columns must be numeric':
# coerce and retry
... Prevention
- Run df.dtypes on the target columns before every regression call.
- pd.to_numeric(errors='coerce') + dropna() any stringly-typed numeric columns at ingest.
- Encode categoricals with get_dummies instead of passing them raw.
When it happens
Trigger: Calling obb.econometrics.ols() (or the regression router command at line ~256) with y_column or an entry in x_columns referring to a string/categorical/date column; passing a dataset where numeric columns are stored as object dtype after JSON round-tripping.
Common situations: Loading data from CSV/JSON where numbers arrive as strings, selecting a date or symbol column as a regressor by mistake, or provider data whose schema changed a field from float to string between versions.
Related errors
- This analysis requires at least 3 items in the dataset.
- Calculation asks for at least last {window} days of data
- Error: expected data with numeric values.
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/4c431f3057449a0d.
Report an issue: GitHub.