preprocessing.checking.check_exog(exog, allow_nan= True , series_id= '`exog`' )
Validate that exog is a pandas Series or DataFrame.
This function ensures that exogenous variables meet basic requirements: - Must be a pandas Series or DataFrame - If Series, must have a name - Optionally warns if NaN values are present
Parameters
exog
Union [pd .Series , pd .DataFrame ]
Exogenous variable/s included as predictor/s.
required
allow_nan
bool
If True, allows NaN values but issues a warning. If False, raises no warning about NaN values. Defaults to True.
True
series_id
str
Identifier of the series used in error messages. Defaults to “exog”.
'exog'
Raises
TypeError
If exog is not a pandas Series or DataFrame.
ValueError
If exog is a Series without a name.
Warns
If allow_nan=True and exog contains NaN values.
Examples
import pandas as pd
from spotforecast2_safe.preprocessing.checking import check_exog
# Valid DataFrame — no error raised
exog_df = pd.DataFrame({"temp" : [20 , 21 , 22 ], "humidity" : [50 , 55 , 60 ]})
check_exog(exog_df)
# Valid Series with name — no error raised
exog_series = pd.Series([1 , 2 , 3 ], name= "temperature" )
check_exog(exog_series)
# Invalid: Series without name
exog_no_name = pd.Series([1 , 2 , 3 ])
try :
check_exog(exog_no_name)
except ValueError as e:
print (f"ValueError: { e} " )
# Invalid: not a Series/DataFrame
try :
check_exog([1 , 2 , 3 ])
except TypeError as e:
print (f"TypeError: { e} " )
ValueError: When `exog` is a pandas Series, it must have a name.
TypeError: `exog` must be a pandas Series or DataFrame. Got <class 'list'>.