preprocessing.checking.check_exog_dtypes

preprocessing.checking.check_exog_dtypes(
    exog,
    call_check_exog=True,
    series_id='`exog`',
)

Check that exogenous variables have valid data types (int, float, category).

This function validates that the exogenous variables (Series or DataFrame) contain only supported data types: integer, float, or category. It issues a warning if other types (like object/string) are found, as these may cause issues with some machine learning estimators.

It also strictly enforces that categorical columns must have integer categories.

Parameters

Name Type Description Default
exog Union[pd.Series, pd.DataFrame] Exogenous variables to check. required
call_check_exog bool If True, calls check_exog() first to ensure basic validity. Defaults to True. True
series_id str Identifier used in warning/error messages. Defaults to “exog”. 'exog'

Raises

Name Type Description
TypeError If categorical columns contain non-integer categories.

Warns

If columns with unsupported data types (not int, float, category) are found.

Examples

import warnings

import pandas as pd

from spotforecast2_safe.exceptions import DataTypeWarning
from spotforecast2_safe.preprocessing.checking import check_exog_dtypes

# Valid types (float, int) — no warning
df_valid = pd.DataFrame({"a": [1.0, 2.0, 3.0], "b": [1, 2, 3]})
check_exog_dtypes(df_valid)

# Invalid type (object/string) — issues DataTypeWarning about column 'b'
df_invalid = pd.DataFrame({"a": [1, 2, 3], "b": ["x", "y", "z"]})
with warnings.catch_warnings(record=True) as caught:
    warnings.simplefilter("always")
    check_exog_dtypes(df_invalid)
assert len(caught) == 1
assert issubclass(caught[0].category, DataTypeWarning)
print(f"Warning issued: {caught[0].category.__name__}")

# Valid categorical (with integer categories) — no warning
df_cat = pd.DataFrame({"a": [1, 2, 1]})
df_cat["a"] = df_cat["a"].astype("category")
check_exog_dtypes(df_cat)
print("All checks passed.")
Warning issued: DataTypeWarning
All checks passed.