Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update add_constrs type hints and docs #85

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions src/gurobipy_pandas/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,29 +193,63 @@ def add_vars(
raise ValueError("`pandas_obj` must be an index, series, or dataframe")


# Two overloads are used here to specify that at least one of the left- and
# right-hand sides must be a series (the other can be a single expression).


@overload
def add_constrs(
model: gp.Model,
lhs: Union[pd.Series, float],
lhs: pd.Series,
sense: Union[pd.Series, str],
rhs: Union[pd.Series, float],
rhs: Union[pd.Series, gp.Var, gp.LinExpr, gp.QuadExpr, float],
*,
name: Optional[str] = None,
index_formatter: Union[str, Callable, Mapping[str, Callable]] = "default",
) -> pd.Series:
"""Add a constraint to the model for each row in lhs & rhs.
... # pragma: no cover


@overload
def add_constrs(
model: gp.Model,
lhs: Union[pd.Series, gp.Var, gp.LinExpr, gp.QuadExpr, float],
sense: Union[pd.Series, str],
rhs: pd.Series,
*,
name: Optional[str] = None,
index_formatter: Union[str, Callable, Mapping[str, Callable]] = "default",
) -> pd.Series:
... # pragma: no cover


def add_constrs(
model,
lhs,
sense,
rhs,
*,
name=None,
index_formatter="default",
) -> pd.Series:
"""Add a constraint to the model for each row in lhs & rhs. At least one of
`lhs` and `rhs` must be a Series, while the other side may be a constant or a
single gurobipy expression. If both sides are Series, then their indexes
must match.

Parameters
----------
model : Model
A Gurobi model to which new constraints will be added
lhs : Series
A series of expressions forming the left hand side of constraints
A series of expressions forming the left hand side of constraints, a
constant, or a single expression.
sense : Series or str
Constraint sense; can be a series if senses vary, or a single string
if all constraints have the same sense
rhs : Series or float
A series of expressions forming the right hand side of constraints,
or a common constant
A series of expressions forming the right hand side of constraints, a
constant, or a single expression.
name : str
Used as the returned series name, as well as the base name for added
Gurobi constraints. Constraint name suffixes come from the lhs/rhs
Expand Down