def pivot_lookup()

in msticpy/datamodel/pivot_register.py [0:0]


    def pivot_lookup(*args, **kwargs) -> pd.DataFrame:
        """
        Lookup Pivot function from Entity or parameter values.

        Parameters
        ----------
        data: Union[str, List[str], pd.DataFrame]
            Not used if querying the entity value itself

        Returns
        -------
        pd.DataFrame
            DataFrame of Pivot function results.

        """
        # remove and save the join kw, if specified (so it doesn't interfere
        # with other operations and doesn't get sent to the function)
        join_type, left_on, right_on, j_ignore_case = get_join_params(kwargs)

        input_value = _get_input_value(*args, pivot_reg=pivot_reg, parent_kwargs=kwargs)
        _check_valid_settings_for_input(input_value, pivot_reg)

        # If the input_value is not a DF convert it into one and return the DF,
        # the column with the input value(s) plus the param dict that we're going
        # to send to the function. This is going to look like:
        # {"data": input_df, "src_column": input_column}
        input_df, input_column, param_dict = _create_input_df(
            input_value, pivot_reg, parent_kwargs=kwargs
        )

        # Add any static parameters for the function to our params dict
        param_dict.update(pivot_reg.func_static_params or {})

        # Call the target function and collect the results
        if pivot_reg.input_type == "value":
            if not pivot_reg.can_iterate and len(input_df) > 1:
                raise TypeError(
                    "The function does not support multiple input values.",
                    "Try again with a single row/value as input.",
                    "E.g. func(data=df.iloc[N], column=...)",
                )
            result_df = _iterate_func(
                target_func, input_df, input_column, pivot_reg, **kwargs
            )
        else:
            result_df = target_func(**param_dict, **kwargs)  # type: ignore
        merge_key = pivot_reg.func_out_column_name or input_column

        # If requested to join to input
        # and this function is returning a DataFrame
        if join_type and not pivot_reg.return_raw_output:
            left_on = left_on or input_column
            right_on = right_on or merge_key
            return join_result(
                input_df=input_df,
                result_df=result_df,
                how=join_type,
                left_on=left_on,
                right_on=right_on,
                ignore_case=j_ignore_case,
            ).drop(columns="src_row_index", errors="ignore")
        return result_df