Skip to content

Commit 36b036e

Browse files
committed
chore: remove small val filtering
1 parent 6a72e55 commit 36b036e

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

linopy/io.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
concat_kwargs = dict(dim=CONCAT_DIM, coords="minimal")
4141

4242
TQDM_COLOR = "#80bfff"
43-
COEFF_THRESHOLD = 1e-12
4443

4544

4645
def handle_batch(batch: list[str], f: TextIOWrapper, batch_size: int) -> list[str]:
@@ -551,10 +550,8 @@ def objective_to_file_polars(
551550
f.write(f"{sense}\n\nobj:\n\n".encode())
552551
df = m.objective.to_polars()
553552

554-
# Filter out zero coefficients like the regular LP version does
555553
if m.is_linear:
556-
df_filtered = df.filter(pl.col("coeffs").abs() > COEFF_THRESHOLD)
557-
objective_write_linear_terms_polars(f, df_filtered, print_variable)
554+
objective_write_linear_terms_polars(f, df, print_variable)
558555

559556
elif m.is_quadratic:
560557
linear_terms = df.filter(pl.col("vars1").eq(-1) | pl.col("vars2").eq(-1))
@@ -564,13 +561,9 @@ def objective_to_file_polars(
564561
.otherwise(pl.col("vars1"))
565562
.alias("vars")
566563
)
567-
# Filter out zero coefficients
568-
linear_terms = linear_terms.filter(pl.col("coeffs").abs() > COEFF_THRESHOLD)
569564
objective_write_linear_terms_polars(f, linear_terms, print_variable)
570565

571566
quads = df.filter(pl.col("vars1").ne(-1) & pl.col("vars2").ne(-1))
572-
# Filter out zero coefficients
573-
quads = quads.filter(pl.col("coeffs").abs() > COEFF_THRESHOLD)
574567
objective_write_quadratic_terms_polars(f, quads, print_variable)
575568

576569

@@ -738,20 +731,6 @@ def constraints_to_file_polars(
738731
for con_slice in con.iterate_slices(slice_size):
739732
df = con_slice.to_polars()
740733

741-
# Filter out rows with zero coefficients or invalid variables - but KEEP RHS rows
742-
# RHS rows have null coeffs/vars but contain the constraint sign/rhs
743-
df = df.filter(
744-
# Keep RHS rows (have sign/rhs but null coeffs/vars)
745-
(pl.col("sign").is_not_null() & pl.col("rhs").is_not_null())
746-
|
747-
# OR keep valid coefficient rows
748-
(
749-
(pl.col("coeffs").abs() > COEFF_THRESHOLD)
750-
& (pl.col("vars").is_not_null())
751-
& (pl.col("vars") >= 0)
752-
)
753-
)
754-
755734
if df.height == 0:
756735
continue
757736

@@ -770,9 +749,10 @@ def constraints_to_file_polars(
770749
if valid.height == 0:
771750
continue
772751

752+
# Keep only constraints that have both parts
773753
df = df.join(valid.select("labels"), on="labels", how="inner")
774754

775-
# Sort by labels for proper grouping and mark first/last occurrences
755+
# Sort by labels and mark first/last occurrences
776756
df = df.sort("labels").with_columns(
777757
[
778758
pl.when(pl.col("labels").is_first_distinct())

0 commit comments

Comments
 (0)