baybe.utils.dataframe.fuzzy_row_match¶
- baybe.utils.dataframe.fuzzy_row_match(left_df: DataFrame, right_df: DataFrame, parameters: Sequence[Parameter], *, keep_unmatched: bool = False)[source]¶
Match rows of the right dataframe to rows of the left dataframe.
This is useful for matching measurements to entries in the search space, e.g. to detect which ones have been measured. For categorical parameters, there needs to be an exact match with any of the allowed values. For numerical parameters, the points with the smallest deviation are considered.
Note
This function assumes that the dataframes contain only allowed values as specified in the parameter objects. No further validation to assert this is done.
- Parameters:
left_df (
DataFrame) – The data that serves as lookup reference.right_df (
DataFrame) – The data that is checked for matching rows in the left dataframe.parameters (
Sequence[Parameter]) – Parameter objects that identify the relevant column names and how matching is performed.keep_unmatched (
bool) – IfTrue, return one index per row ofright_df, with missing indices for unmatched rows. Otherwise, omit unmatched rows.
- Return type:
Index- Returns:
The indices of the matching rows in
left_df, in the order of the rows inright_df. Ifkeep_unmatchedisTrue, unmatched rows have missing indices, including whenleft_dfis empty.- Raises:
ValueError – If either
left_dforright_dfdoes not contain columns for each entry in parameters.