preprocessing.checking.check_y(y, series_id= '`y`' )
Validate that y is a pandas Series without missing values.
This function ensures that the input time series meets the basic requirements for forecasting: it must be a pandas Series and must not contain any NaN values.
Parameters
y
Any
Time series values to validate.
required
series_id
str
Identifier of the series used in error messages. Defaults to “y”.
'y'
Examples
import numpy as np
import pandas as pd
from spotforecast2_safe.preprocessing.checking import check_y
# Valid series — no error raised
y = pd.Series([1 , 2 , 3 , 4 , 5 ])
check_y(y)
# Invalid: not a Series
try :
check_y([1 , 2 , 3 ])
except TypeError as e:
print (f"TypeError: { e} " )
# Invalid: contains NaN
y_with_nan = pd.Series([1 , 2 , np.nan, 4 ])
try :
check_y(y_with_nan)
except ValueError as e:
print (f"ValueError: { e} " )
TypeError: `y` must be a pandas Series with a DatetimeIndex or a RangeIndex. Found <class 'list'>.
ValueError: `y` has missing values.