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

[pre-commit.ci] pre-commit autoupdate #408

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- id: trailing-whitespace
- id: check-merge-conflict
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.9.4
hooks:
- id: ruff
args: [--fix]
Expand All @@ -25,7 +25,7 @@ repos:
hooks:
- id: blackdoc
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.1
hooks:
- id: codespell
types_or: [python, rst, markdown]
Expand Down
4 changes: 2 additions & 2 deletions linopy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@
elif size == 1:
expr = print_single_expression(self.coeffs, self.vars, 0, self.model)
lines.append(
f"{header_string}\n{'-'*len(header_string)}\n{expr} {SIGNS_pretty[self.sign.item()]} {self.rhs.item()}"
f"{header_string}\n{'-' * len(header_string)}\n{expr} {SIGNS_pretty[self.sign.item()]} {self.rhs.item()}"
)
else:
lines.append(f"{header_string}\n{'-'*len(header_string)}\n<empty>")
lines.append(f"{header_string}\n{'-' * len(header_string)}\n<empty>")

Check warning on line 325 in linopy/constraints.py

View check run for this annotation

Codecov / codecov/patch

linopy/constraints.py#L325

Added line #L325 was not covered by tests

return "\n".join(lines)

Expand Down
18 changes: 9 additions & 9 deletions linopy/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@
expr = print_single_expression(
self.coeffs, self.vars, self.const, self.model
)
lines.append(f"{header_string}\n{'-'*len(header_string)}\n{expr}")
lines.append(f"{header_string}\n{'-' * len(header_string)}\n{expr}")
else:
lines.append(f"{header_string}\n{'-'*len(header_string)}\n<empty>")
lines.append(f"{header_string}\n{'-' * len(header_string)}\n<empty>")

Check warning on line 453 in linopy/expressions.py

View check run for this annotation

Codecov / codecov/patch

linopy/expressions.py#L453

Added line #L453 was not covered by tests

return "\n".join(lines)

Expand Down Expand Up @@ -1875,7 +1875,7 @@
return ScalarLinearExpression(coeffs, vars, self.model)
elif not isinstance(other, ScalarLinearExpression):
raise TypeError(
"unsupported operand type(s) for +: " f"{type(self)} and {type(other)}"
f"unsupported operand type(s) for +: {type(self)} and {type(other)}"
)

coeffs = self.coeffs + other.coeffs
Expand All @@ -1901,7 +1901,7 @@
other = other.to_scalar_linexpr(1)
elif not isinstance(other, ScalarLinearExpression):
raise TypeError(
"unsupported operand type(s) for -: " f"{type(self)} and {type(other)}"
f"unsupported operand type(s) for -: {type(self)} and {type(other)}"
)

return ScalarLinearExpression(
Expand All @@ -1918,7 +1918,7 @@
def __mul__(self, other: float | int) -> ScalarLinearExpression:
if not isinstance(other, (int, float, np.number)):
raise TypeError(
"unsupported operand type(s) for *: " f"{type(self)} and {type(other)}"
f"unsupported operand type(s) for *: {type(self)} and {type(other)}"
)

return ScalarLinearExpression(
Expand All @@ -1931,7 +1931,7 @@
def __div__(self, other: float | int) -> ScalarLinearExpression:
if not isinstance(other, (int, float, np.number)):
raise TypeError(
"unsupported operand type(s) for /: " f"{type(self)} and {type(other)}"
f"unsupported operand type(s) for /: {type(self)} and {type(other)}"
)
return self.__mul__(1 / other)

Expand All @@ -1941,23 +1941,23 @@
def __le__(self, other: int | float) -> AnonymousScalarConstraint:
if not isinstance(other, (int, float, np.number)):
raise TypeError(
"unsupported operand type(s) for <=: " f"{type(self)} and {type(other)}"
f"unsupported operand type(s) for <=: {type(self)} and {type(other)}"
)

return constraints.AnonymousScalarConstraint(self, LESS_EQUAL, other)

def __ge__(self, other: int | float) -> AnonymousScalarConstraint:
if not isinstance(other, (int, float, np.number)):
raise TypeError(
"unsupported operand type(s) for >=: " f"{type(self)} and {type(other)}"
f"unsupported operand type(s) for >=: {type(self)} and {type(other)}"
)

return constraints.AnonymousScalarConstraint(self, GREATER_EQUAL, other)

def __eq__(self, other: int | float) -> AnonymousScalarConstraint: # type: ignore
if not isinstance(other, (int, float, np.number)):
raise TypeError(
"unsupported operand type(s) for ==: " f"{type(self)} and {type(other)}"
f"unsupported operand type(s) for ==: {type(self)} and {type(other)}"
)

return constraints.AnonymousScalarConstraint(self, EQUAL, other)
Expand Down
10 changes: 5 additions & 5 deletions linopy/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def to_lp_file(
)
f.write("end\n")

logger.info(f" Writing time: {round(time.time()-start, 2)}s")
logger.info(f" Writing time: {round(time.time() - start, 2)}s")


def objective_write_linear_terms_polars(f, df):
Expand Down Expand Up @@ -394,14 +394,14 @@ def objective_to_file_polars(m, f, progress=False):
objective_write_linear_terms_polars(f, df)

elif m.is_quadratic:
lins = df.filter(pl.col("vars1").eq(-1) | pl.col("vars2").eq(-1))
lins = lins.with_columns(
linear_terms = df.filter(pl.col("vars1").eq(-1) | pl.col("vars2").eq(-1))
linear_terms = linear_terms.with_columns(
pl.when(pl.col("vars1").eq(-1))
.then(pl.col("vars2"))
.otherwise(pl.col("vars1"))
.alias("vars")
)
objective_write_linear_terms_polars(f, lins)
objective_write_linear_terms_polars(f, linear_terms)

quads = df.filter(pl.col("vars1").ne(-1) & pl.col("vars2").ne(-1))
objective_write_quadratic_terms_polars(f, quads)
Expand Down Expand Up @@ -586,7 +586,7 @@ def to_lp_file_polars(
)
f.write(b"end\n")

logger.info(f" Writing time: {round(time.time()-start, 2)}s")
logger.info(f" Writing time: {round(time.time() - start, 2)}s")


def to_file(
Expand Down
6 changes: 3 additions & 3 deletions linopy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,9 @@ def add_constraints(
if mask is not None:
mask = as_dataarray(mask).astype(bool)
# TODO: simplify
assert set(mask.dims).issubset(
data.dims
), "Dimensions of mask not a subset of resulting labels dimensions."
assert set(mask.dims).issubset(data.dims), (
"Dimensions of mask not a subset of resulting labels dimensions."
)

self.check_force_dim_names(data)

Expand Down
10 changes: 5 additions & 5 deletions linopy/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,11 @@ def __repr__(self) -> str:
mask_str = f" - {masked_entries} masked entries" if masked_entries else ""
lines.insert(
0,
f"Variable ({shape_str}){mask_str}\n{'-'* (len(shape_str) + len(mask_str) + 11)}",
f"Variable ({shape_str}){mask_str}\n{'-' * (len(shape_str) + len(mask_str) + 11)}",
)
else:
lines.append(
f"Variable\n{'-'*8}\n{print_single_variable(self.model, self.labels.item())}"
f"Variable\n{'-' * 8}\n{print_single_variable(self.model, self.labels.item())}"
)

return "\n".join(lines)
Expand Down Expand Up @@ -1111,9 +1111,9 @@ def __getitem__(self, keys: Any) -> ScalarVariable:
# return single scalar
if not object.labels.ndim:
return ScalarVariable(object.labels.item(), object.model)
assert object.labels.ndim == len(
keys
), f"expected {object.labels.ndim} keys, got {len(keys)}."
assert object.labels.ndim == len(keys), (
f"expected {object.labels.ndim} keys, got {len(keys)}."
)
key = dict(zip(object.labels.dims, keys))
keys = [object.labels.get_index(k).get_loc(v) for k, v in key.items()]
return ScalarVariable(object.labels.data[tuple(keys)], object.model)
Expand Down
Loading