planned_controls_to_dataarray#

pymc_marketing.mmm.utils.planned_controls_to_dataarray(control_data, date_column, dims, control_columns)[source]#

Convert planned control values to a labelled DataArray.

Parameters:
  • control_data (DataFrame | DataArray) – A DataFrame with the date column, one column per dim and one column per control (other columns are ignored), or a DataArray with dims ("date", *dims, "control") and a labelled coordinate for each.

  • date_column (str) – Name of the DataFrame’s date column.

  • dims (list[str] | tuple[str, ...]) – The model’s dims besides date, such as ("geo",).

  • control_columns (list[str]) – The model’s control columns. Every one of them is required.

Return type:

xr.DataArray

Returns:

The planned values with dims ("date", *dims, "control"), in any order, and a datetime date coordinate.

Raises:
  • ValueError – If a date, dim or control column or coordinate is missing or unlabelled, a row or label is duplicated, or a DataArray names a control that is not in control_columns.

  • TypeError – If control_data is neither a DataFrame nor a DataArray.