src/estimagic/parameters/check_constraints.py
def check_fixes_and_bounds(pp, pc):
    """Check fixes.

    Warn the user if he fixes a parameter to a value even though that parameter has
    a different non-nan value in params

    check that fixes are compatible with other constraints.

    Args:
        pp (pd.DataFrame): see :ref:`params`.
        pc (list): Processed and consolidated constraints.
    """
    # warn about fixes to a different value that what is in the "value" column
    problematic_fixes = pp.query(
        "value != _fixed_value & _fixed_value.notnull() & value.notnull()",
        engine="python",
    )

    warn_msg = (
        "The following parameters were fixed to a different value than their start "
        "value. The start values are overwritten with the fixed values. "
        "You can ignore this message if you did this on purpose. :\n\n {}."
    )

    if len(problematic_fixes) > 0:
        warnings.warn(warn_msg.format(problematic_fixes[["value", "_fixed_value"]]))

    # Check fixes and bounds are compatible with other constraints
    prob_msg = (
        "{} constraints are incompatible with fixes or bounds. "
        "This is violated for:\n{}"
    )

    cov_msg = (
        "{} constraints are incompatible with fixes or bounds except for the first "
        "parameter. This is violated for:\n{}"
    )

    for constr in pc:
        if constr["type"] in ["covariance", "sdcorr"]:
            subset = pp.iloc[constr["index"][1:]]
            if subset["_is_fixed_to_value"].any():
                problematic = subset[subset["_is_fixed_to_value"]].index
                raise ValueError(cov_msg.format(constr["type"], problematic))
            if np.isfinite(subset[["lower_bound", "upper_bound"]]).any(axis=None):
                problematic = (
                    subset.replace([-np.inf, np.inf], np.nan).dropna(how="all").index
                )
                raise ValueError(cov_msg.format(constr["type"], problematic))
        elif constr["type"] == "probability":
            subset = pp.iloc[constr["index"]]
            if subset["_is_fixed_to_value"].any():
                problematic = subset[subset["_is_fixed_to_value"]].index
                raise ValueError(prob_msg.format(constr["type"], problematic))
            if np.isfinite(subset[["lower_bound", "upper_bound"]]).any(axis=None):
                problematic = (
                    subset.replace([-np.inf, np.inf], np.nan).dropna(how="all").index
                )
                raise ValueError(prob_msg.format(constr["type"], problematic))

    invalid = pp.query("lower_bound >= upper_bound")[["lower_bound", "upper_bound"]]
    msg = (
        "lower_bound must be strictly smaller than upper_bound. "
        + f"This is violated for:\n{invalid}"
    )
    if len(invalid) > 0:
        raise ValueError(msg)
Check fixes.

    Warn the user if he fixes a parameter to a value even though that parameter has
    a different non-nan value in params

    check that fixes are compatible with other constraints.

    Args:
        pp (pd.DataFrame): see :ref:`params`.
        pc (list): Processed and consolidated constraints.
    
Check fixes.
Warn the user if he fixes a parameter to a value even though that parameter has
a different non-nan value in params

check that fixes are compatible with other constraints.
Check fixes . Warn the user if he fixes a parameter to a value even though that parameter has a different non - nan value in params check that fixes are compatible with other constraints .
def check_fixes_and_bounds(pp, pc):
    problematic_fixes = pp.query(
        "value != _fixed_value & _fixed_value.notnull() & value.notnull()",
        engine="python",
    )
    warn_msg = (
        "The following parameters were fixed to a different value than their start "
        "value. The start values are overwritten with the fixed values. "
        "You can ignore this message if you did this on purpose. :\n\n {}."
    )
    if len(problematic_fixes) > 0:
        warnings.warn(warn_msg.format(problematic_fixes[["value", "_fixed_value"]]))
    prob_msg = (
        "{} constraints are incompatible with fixes or bounds. "
        "This is violated for:\n{}"
    )
    cov_msg = (
        "{} constraints are incompatible with fixes or bounds except for the first "
        "parameter. This is violated for:\n{}"
    )
    for constr in pc:
        if constr["type"] in ["covariance", "sdcorr"]:
            subset = pp.iloc[constr["index"][1:]]
            if subset["_is_fixed_to_value"].any():
                problematic = subset[subset["_is_fixed_to_value"]].index
                raise ValueError(cov_msg.format(constr["type"], problematic))
            if np.isfinite(subset[["lower_bound", "upper_bound"]]).any(axis=None):
                problematic = (
                    subset.replace([-np.inf, np.inf], np.nan).dropna(how="all").index
                )
                raise ValueError(cov_msg.format(constr["type"], problematic))
        elif constr["type"] == "probability":
            subset = pp.iloc[constr["index"]]
            if subset["_is_fixed_to_value"].any():
                problematic = subset[subset["_is_fixed_to_value"]].index
                raise ValueError(prob_msg.format(constr["type"], problematic))
            if np.isfinite(subset[["lower_bound", "upper_bound"]]).any(axis=None):
                problematic = (
                    subset.replace([-np.inf, np.inf], np.nan).dropna(how="all").index
                )
                raise ValueError(prob_msg.format(constr["type"], problematic))
    invalid = pp.query("lower_bound >= upper_bound")[["lower_bound", "upper_bound"]]
    msg = (
        "lower_bound must be strictly smaller than upper_bound. "
        + f"This is violated for:\n{invalid}"
    )
    if len(invalid) > 0:
        raise ValueError(msg)
def check_fixes_and_bounds ( pp , pc ) : problematic_fixes = pp . query ( "value != _fixed_value & _fixed_value.notnull() & value.notnull()" , engine = "python" , ) warn_msg = ( "The following parameters were fixed to a different value than their start " "value. The start values are overwritten with the fixed values. " "You can ignore this message if you did this on purpose. :\n\n {}." ) if len ( problematic_fixes ) > 0 : warnings . warn ( warn_msg . format ( problematic_fixes [ [ "value" , "_fixed_value" ] ] ) ) prob_msg = ( "{} constraints are incompatible with fixes or bounds. " "This is violated for:\n{}" ) cov_msg = ( "{} constraints are incompatible with fixes or bounds except for the first " "parameter. This is violated for:\n{}" ) for constr in pc : if constr [ "type" ] in [ "covariance" , "sdcorr" ] : subset = pp . iloc [ constr [ "index" ] [ 1 : ] ] if subset [ "_is_fixed_to_value" ] . any ( ) : problematic = subset [ subset [ "_is_fixed_to_value" ] ] . index raise ValueError ( cov_msg . format ( constr [ "type" ] , problematic ) ) if np . isfinite ( subset [ [ "lower_bound" , "upper_bound" ] ] ) . any ( axis = None ) : problematic = ( subset . replace ( [ - np . inf , np . inf ] , np . nan ) . dropna ( how = "all" ) . index ) raise ValueError ( cov_msg . format ( constr [ "type" ] , problematic ) ) elif constr [ "type" ] == "probability" : subset = pp . iloc [ constr [ "index" ] ] if subset [ "_is_fixed_to_value" ] . any ( ) : problematic = subset [ subset [ "_is_fixed_to_value" ] ] . index raise ValueError ( prob_msg . format ( constr [ "type" ] , problematic ) ) if np . isfinite ( subset [ [ "lower_bound" , "upper_bound" ] ] ) . any ( axis = None ) : problematic = ( subset . replace ( [ - np . inf , np . inf ] , np . nan ) . dropna ( how = "all" ) . index ) raise ValueError ( prob_msg . format ( constr [ "type" ] , problematic ) ) invalid = pp . query ( "lower_bound >= upper_bound" ) [ [ "lower_bound" , "upper_bound" ] ] msg = ( "lower_bound must be strictly smaller than upper_bound. " + f"This is violated for:\n{invalid}" ) if len ( invalid ) > 0 : raise ValueError ( msg )
Check fixes.
Check fixes .
"""Check fixes.

    Warn the user if he fixes a parameter to a value even though that parameter has
    a different non-nan value in params

    check that fixes are compatible with other constraints.

    Args:
        pp (pd.DataFrame): see :ref:`params`.
        pc (list): Processed and consolidated constraints.
    """ # warn about fixes to a different value that what is in the "value" column # Check fixes and bounds are compatible with other constraints
pp
None
pc
Processed and consolidated constraints.
Processed and consolidated constraints .