docstr: Test that conditional seasonality is correctly incorporated by the model
docstr_tok: ["Test","that","conditional","seasonality","is","correctly","incorporated","by","the","model"]
code: def test_conditional_seasonality(self):
      """
      Test that conditional seasonality is correctly incorporated by the model
      """
      duration = 395
      horizon = 7
      df = pd.DataFrame()
      df["ds"] = pd.date_range(start="2022-01-02", periods=395)
      df["y"] = [i + 10 * (i % 7 == 0) for i in range(duration)]
      df["is_sunday"] = df["ds"].apply(lambda x: int(x.weekday() == 6))
  
      ts = TimeSeries.from_dataframe(
          df[:-horizon], time_col="ds", value_cols="y", freq="D"
      )
      future_covariates = TimeSeries.from_dataframe(
          df, time_col="ds", value_cols=["is_sunday"], freq="D"
      )
      expected_result = TimeSeries.from_dataframe(
          df[-horizon:], time_col="ds", value_cols="y", freq="D"
      )
  
      model = Prophet(seasonality_mode="additive")
      model.add_seasonality(
          name="weekly_sun",
          seasonal_periods=7,
          fourier_order=2,
          condition_name="is_sunday",
      )
  
      model.fit(ts, future_covariates=future_covariates)
  
      forecast = model.predict(
          horizon, future_covariates=future_covariates
      )
  
      for val_i, pred_i in zip(
          expected_result.univariate_values(),
          forecast.univariate_values(),
      ):
          assert abs(val_i - pred_i) < 0.1
  
      invalid_future_covariates = future_covariates.with_values(
          np.reshape(
              np.random.randint(0, 3, duration), (-1, 1, 1)
          ).astype("float")
      )
  
      with pytest.raises(ValueError):
          model.fit(ts, future_covariates=invalid_future_covariates)
  
      with pytest.raises(ValueError):
          model.fit(
              ts,
              future_covariates=invalid_future_covariates.drop_columns(
                  "is_sunday"
              ),
          )
  
file_path: darts/darts/tests/models/forecasting/test_prophet.py
imports: from unittest.mock import Mock
  import numpy
  import pandas
  import pytest
  from darts import TimeSeries
  from darts.logging import get_logger
  from darts.models import NotImportedModule, Prophet
  from darts.utils import timeseries_generation
label_desc: Use image node_id 9 for calling the TestProphet obj's underlying member method code with example usage: obj.test_conditional_seasonality() without return types