A user is getting a `UnprocessableEntityError: sta...
# support
t
A user is getting a
UnprocessableEntityError: status_code: 422, body: detail=None
error. Code and full error message in thread. Maybe for @José Morales @Marco or @Yibei. Thanks so much!
1
Copy code
# TimeGPT Function
timegpt_fcst_ex_vars_df = timegpt.forecast(df=df_train, X_df=df_test.drop("ground_no2", axis=1), time_col='date', target_col='ground_no2', id_col='station', h=min_len, freq='D')
The following is the complete error:
Copy code
INFO:nixtlats.timegpt:Validating inputs...
INFO:nixtlats.timegpt:Preprocessing dataframes...
WARNING:nixtlats.timegpt:The specified horizon "h" exceeds the model horizon. This may lead to less accurate forecasts. Please consider using a smaller horizon.
INFO:nixtlats.timegpt:Using the following exogenous variables: satellite_no2, curr_temp_celsius, curr_surface_net_solar_radiation, curr_surface_pressure, prev_temp_celsius, prev_surface_net_solar_radiation
INFO:nixtlats.timegpt:Calling Forecast Endpoint...
---------------------------------------------------------------------------
UnprocessableEntityError                  Traceback (most recent call last)
Cell In[23], line 2
      1 # TimeGPT Function
----> 2 timegpt_fcst_ex_vars_df = timegpt.forecast(df=df_train, X_df=df_test.drop("ground_no2", axis=1), time_col='date', target_col='ground_no2', id_col='station', h=min_len, freq='D')

File ~/miniforge3/envs/ml/lib/python3.10/site-packages/nixtlats/timegpt.py:1078, in TimeGPT.forecast(self, df, h, freq, id_col, time_col, target_col, X_df, level, finetune_steps, clean_ex_first, validate_token, add_history, date_features, date_features_to_one_hot, model, num_partitions)
   1010 """Forecast your time series using TimeGPT.
   1011 
   1012 Parameters
   (...)
   1075     predictions (if level is not None).
   1076 """
   1077 if isinstance(df, pd.DataFrame):
-> 1078     return self._forecast(
   1079         df=df,
   1080         h=h,
   1081         freq=freq,
   1082         id_col=id_col,
   1083         time_col=time_col,
   1084         target_col=target_col,
   1085         X_df=X_df,
   1086         level=level,
   1087         finetune_steps=finetune_steps,
   1088         clean_ex_first=clean_ex_first,
   1089         validate_token=validate_token,
   1090         add_history=add_history,
   1091         date_features=date_features,
   1092         date_features_to_one_hot=date_features_to_one_hot,
   1093         model=model,
   1094         num_partitions=num_partitions,
   1095     )
   1096 else:
   1097     dist_timegpt = self._instantiate_distributed_timegpt()

File ~/miniforge3/envs/ml/lib/python3.10/site-packages/nixtlats/timegpt.py:625, in validate_model_parameter.<locals>.wrapper(self, *args, **kwargs)
    620 if "model" in kwargs and kwargs["model"] not in self.supported_models:
    621     raise ValueError(
    622         f'unsupported model: {kwargs["model"]} '
    623         f'supported models: {", ".join(self.supported_models)}'
    624     )
--> 625 return func(self, *args, **kwargs)

File ~/miniforge3/envs/ml/lib/python3.10/site-packages/nixtlats/timegpt.py:643, in partition_by_uid.<locals>.wrapper(self, num_partitions, **kwargs)
    641 def wrapper(self, num_partitions, **kwargs):
    642     if num_partitions is None or num_partitions == 1:
--> 643         return func(self, **kwargs, num_partitions=1)
    644     df = kwargs.pop("df")
    645     X_df = kwargs.pop("X_df", None)

File ~/miniforge3/envs/ml/lib/python3.10/site-packages/nixtlats/timegpt.py:779, in _TimeGPT._forecast(self, df, h, freq, id_col, time_col, target_col, X_df, level, finetune_steps, clean_ex_first, validate_token, add_history, date_features, date_features_to_one_hot, model, num_partitions)
    761     raise Exception("Token not valid, please email ops@nixtla.io")
    762 timegpt_model = _TimeGPTModel(
    763     client=self.client,
    764     h=h,
   (...)
    777     max_wait_time=self.max_wait_time,
    778 )
--> 779 fcst_df = timegpt_model.forecast(df=df, X_df=X_df, add_history=add_history)
    780 self.weights_x = timegpt_model.weights_x
    781 return fcst_df

File ~/miniforge3/envs/ml/lib/python3.10/site-packages/nixtlats/timegpt.py:487, in _TimeGPTModel.forecast(self, df, X_df, add_history)
    476 main_logger.info("Calling Forecast Endpoint...")
    477 payload = dict(
    478     y=y,
    479     x=x,
   (...)
    485     model=self.model,
    486 )
--> 487 response_timegpt = self._call_api(
    488     self.client.timegpt_multi_series,
    489     payload,
    490 )
    491 if "weights_x" in response_timegpt:
    492     self.weights_x = pd.DataFrame(
    493         {
    494             "features": self.x_cols,
    495             "weights": response_timegpt["weights_x"],
    496         }
    497     )

File ~/miniforge3/envs/ml/lib/python3.10/site-packages/nixtlats/timegpt.py:161, in _TimeGPTModel._call_api(self, method, kwargs)
    160 def _call_api(self, method, kwargs):
--> 161     response = self._retry_strategy()(method)(**kwargs)
    162     if "data" in response:
    163         response = response["data"]

File ~/miniforge3/envs/ml/lib/python3.10/site-packages/tenacity/__init__.py:289, in BaseRetrying.wraps.<locals>.wrapped_f(*args, **kw)
    287 @functools.wraps(f)
    288 def wrapped_f(*args: t.Any, **kw: t.Any) -> t.Any:
--> 289     return self(f, *args, **kw)

File ~/miniforge3/envs/ml/lib/python3.10/site-packages/tenacity/__init__.py:379, in Retrying.__call__(self, fn, *args, **kwargs)
    377 retry_state = RetryCallState(retry_object=self, fn=fn, args=args, kwargs=kwargs)
    378 while True:
--> 379     do = self.iter(retry_state=retry_state)
    380     if isinstance(do, DoAttempt):
    381         try:

File ~/miniforge3/envs/ml/lib/python3.10/site-packages/tenacity/__init__.py:314, in BaseRetrying.iter(self, retry_state)
    312 is_explicit_retry = fut.failed and isinstance(fut.exception(), TryAgain)
    313 if not (is_explicit_retry or self.retry(retry_state)):
--> 314     return fut.result()
    316 if self.after is not None:
    317     self.after(retry_state)

File ~/miniforge3/envs/ml/lib/python3.10/concurrent/futures/_base.py:438, in Future.result(self, timeout)
    436     raise CancelledError()
    437 elif self._state == FINISHED:
--> 438     return self.__get_result()
    440 self._condition.wait(timeout)
    442 if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:

File ~/miniforge3/envs/ml/lib/python3.10/concurrent/futures/_base.py:390, in Future.__get_result(self)
    388 if self._exception:
    389     try:
--> 390         raise self._exception
    391     finally:
    392         # Break a reference cycle with the exception in self._exception
    393         self = None

File ~/miniforge3/envs/ml/lib/python3.10/site-packages/tenacity/__init__.py:382, in Retrying.__call__(self, fn, *args, **kwargs)
    380 if isinstance(do, DoAttempt):
    381     try:
--> 382         result = fn(*args, **kwargs)
    383     except BaseException:  # noqa: B902
    384         retry_state.set_exception(sys.exc_info())  # type: ignore[arg-type]

File ~/miniforge3/envs/ml/lib/python3.10/site-packages/nixtlats/client.py:169, in Nixtla.timegpt_multi_series(self, model, freq, level, fh, y, x, clean_ex_first, finetune_steps)
    167     return pydantic.parse_obj_as(typing.Any, _response.json())  # type: ignore
    168 if _response.status_code == 422:
--> 169     raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json()))  # type: ignore
    170 try:
    171     _response_json = _response.json()

UnprocessableEntityError: status_code: 422, body: detail=None
j
Who's the user?
t
j
I believe it's this one, it has a huge error message in the response, it's weird it's showing up as None. Also it seems to be calling a deprecated endpoint, he may be using a very old version of the sdk
t
Thanks, I see the "timegpt_multi_series" has been deprecated and will be removed in 2024-06-21" in there. So, I'll point that out, and suggest he update the sdk he's using.
👍 1
j
The contents of the error message should also help, it's most likely a mismatch in the dates between df and X_df (X_df must be in the future and it probably isn't)
👍 1