baybe.parameters.utils.get_parameters_from_dataframe

baybe.parameters.utils.get_parameters_from_dataframe(df: DataFrame, factory: Callable[[str, Collection[Any]], _TParameter], parameters: list[_TParameter] | None = None)[source]

Create a list of parameters from a dataframe.

Returns one parameter for each column of the given dataframe. By default, the parameters are created using the provided factory, which takes the name of the column and its unique values as arguments. However, there is also the possibility to provide explicit parameter objects with names matching specific columns of the dataframe, to bypass the parameter factory creation for those columns. This allows finer control, for example, to specify custom parameter attributes (e.g. specific optional arguments) compared to what would be provided by the factory. Still, the pre-specified parameters are validated to ensure that they are compatible with the contents of the dataframe.

Parameters:
  • df (DataFrame) – The dataframe from which to create the parameters.

  • factory (Callable[[str, Collection[Any]], TypeVar(_TParameter, bound= Parameter)]) – A parameter factor, creating parameter objects for the columns from the column name and the unique column values.

  • parameters (Optional[list[TypeVar(_TParameter, bound= Parameter)]]) – An optional list of parameter objects to bypass the factory creation for columns whose names match with the parameter names.

Return type:

list[TypeVar(_TParameter, bound= Parameter)]

Returns:

The combined parameter list, containing both the (validated) pre-specified parameters and the parameters inferred from the dataframe.

Raises:
  • ValueError – If several parameters with identical names are provided.

  • ValueError – If a parameter was specified for which no match was found.