src/estimagic/parameters/process_constraints.py
def _process_selectors(constraints, params):
    """Convert the query and loc field of the constraint into position based indices.

    Args:
        constraints (list): List of dictionaries where each dictionary is a constraint.
        params (pd.DataFrame): see :ref:`params`.

    Returns:
        pc (list): The resulting constraint dictionaries contain a new entry
            called 'index' that consists of the positions of the selected parameters.
            If the selected parameters are consecutive entries, the value corresponding
            to 'index' is a list of positions.

    """
    pc = []

    for constr in constraints:
        new_constr = constr.copy()

        if constr["type"] != "pairwise_equality":
            locs = [constr["loc"]] if "loc" in constr else []
            queries = [constr["query"]] if "query" in constr else []
        else:
            locs = new_constr.pop("locs", [])
            queries = new_constr.pop("queries", [])

        positions = pd.Series(data=np.arange(len(params)), index=params.index)

        indices = []
        for loc in locs:
            index = positions.loc[loc].astype(int).tolist()
            index = [index] if not isinstance(index, list) else index
            assert len(set(index)) == len(index), "Duplicates in loc are not allowed."
            indices.append(index)
        for query in queries:
            loc = params.query(query).index
            index = positions.loc[loc].astype(int).tolist()
            index = [index] if not isinstance(index, list) else index
            indices.append(index)

        if constr["type"] == "pairwise_equality":
            assert (
                len(indices) >= 2
            ), "Select at least 2 sets of parameters for pairwise equality constraint!"
            length = len(indices[0])
            for index in indices:
                assert len(index) == length, (
                    "All sets of parameters in pairwise_equality pc must have "
                    "the same length."
                )
        else:
            assert (
                len(indices) == 1
            ), "Either loc or query can be in constraint but not both."

        n_selected = len(indices[0])
        if n_selected >= 1:
            if constr["type"] == "pairwise_equality":
                new_constr["indices"] = indices
            else:
                new_constr["index"] = indices[0]
            pc.append(new_constr)

    return pc
Convert the query and loc field of the constraint into position based indices.

    Args:
        constraints (list): List of dictionaries where each dictionary is a constraint.
        params (pd.DataFrame): see :ref:`params`.

    Returns:
        pc (list): The resulting constraint dictionaries contain a new entry
            called 'index' that consists of the positions of the selected parameters.
            If the selected parameters are consecutive entries, the value corresponding
            to 'index' is a list of positions.

    
Convert the query and loc field of the constraint into position based indices.
Convert the query and loc field of the constraint into position based indices .
def _process_selectors(constraints, params):
    pc = []
    for constr in constraints:
        new_constr = constr.copy()
        if constr["type"] != "pairwise_equality":
            locs = [constr["loc"]] if "loc" in constr else []
            queries = [constr["query"]] if "query" in constr else []
        else:
            locs = new_constr.pop("locs", [])
            queries = new_constr.pop("queries", [])
        positions = pd.Series(data=np.arange(len(params)), index=params.index)
        indices = []
        for loc in locs:
            index = positions.loc[loc].astype(int).tolist()
            index = [index] if not isinstance(index, list) else index
            assert len(set(index)) == len(index), "Duplicates in loc are not allowed."
            indices.append(index)
        for query in queries:
            loc = params.query(query).index
            index = positions.loc[loc].astype(int).tolist()
            index = [index] if not isinstance(index, list) else index
            indices.append(index)
        if constr["type"] == "pairwise_equality":
            assert (
                len(indices) >= 2
            ), "Select at least 2 sets of parameters for pairwise equality constraint!"
            length = len(indices[0])
            for index in indices:
                assert len(index) == length, (
                    "All sets of parameters in pairwise_equality pc must have "
                    "the same length."
                )
        else:
            assert (
                len(indices) == 1
            ), "Either loc or query can be in constraint but not both."
        n_selected = len(indices[0])
        if n_selected >= 1:
            if constr["type"] == "pairwise_equality":
                new_constr["indices"] = indices
            else:
                new_constr["index"] = indices[0]
            pc.append(new_constr)
    return pc
def _process_selectors ( constraints , params ) : pc = [ ] for constr in constraints : new_constr = constr . copy ( ) if constr [ "type" ] != "pairwise_equality" : locs = [ constr [ "loc" ] ] if "loc" in constr else [ ] queries = [ constr [ "query" ] ] if "query" in constr else [ ] else : locs = new_constr . pop ( "locs" , [ ] ) queries = new_constr . pop ( "queries" , [ ] ) positions = pd . Series ( data = np . arange ( len ( params ) ) , index = params . index ) indices = [ ] for loc in locs : index = positions . loc [ loc ] . astype ( int ) . tolist ( ) index = [ index ] if not isinstance ( index , list ) else index assert len ( set ( index ) ) == len ( index ) , "Duplicates in loc are not allowed." indices . append ( index ) for query in queries : loc = params . query ( query ) . index index = positions . loc [ loc ] . astype ( int ) . tolist ( ) index = [ index ] if not isinstance ( index , list ) else index indices . append ( index ) if constr [ "type" ] == "pairwise_equality" : assert ( len ( indices ) >= 2 ) , "Select at least 2 sets of parameters for pairwise equality constraint!" length = len ( indices [ 0 ] ) for index in indices : assert len ( index ) == length , ( "All sets of parameters in pairwise_equality pc must have " "the same length." ) else : assert ( len ( indices ) == 1 ) , "Either loc or query can be in constraint but not both." n_selected = len ( indices [ 0 ] ) if n_selected >= 1 : if constr [ "type" ] == "pairwise_equality" : new_constr [ "indices" ] = indices else : new_constr [ "index" ] = indices [ 0 ] pc . append ( new_constr ) return pc
Convert the query and loc field of the constraint into position based indices.
Convert the query and loc field of the constraint into position based indices .
"""Convert the query and loc field of the constraint into position based indices.

    Args:
        constraints (list): List of dictionaries where each dictionary is a constraint.
        params (pd.DataFrame): see :ref:`params`.

    Returns:
        pc (list): The resulting constraint dictionaries contain a new entry
            called 'index' that consists of the positions of the selected parameters.
            If the selected parameters are consecutive entries, the value corresponding
            to 'index' is a list of positions.

    """
pc (list): The resulting constraint dictionaries contain a new entry
called 'index' that consists of the positions of the selected parameters.
If the selected parameters are consecutive entries, the value corresponding
to 'index' is a list of positions.
pc ( list ) : The resulting constraint dictionaries contain a new entry called ' index ' that consists of the positions of the selected parameters . If the selected parameters are consecutive entries the value corresponding to ' index ' is a list of positions .
constraints
List of dictionaries where each dictionary is a constraint.
List of dictionaries where each dictionary is a constraint .
params
None