File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -361,17 +361,26 @@ def constraints_to_file(
361361 if df .height == 0 :
362362 continue
363363
364- # Ensure each constraint has both coefficient and RHS terms
364+ # <= + inf and >= - inf are unbounded and skipped
365+ rhs_unbounded = pl .col ("rhs" ).is_infinite () & (
366+ pl .when (pl .col ("sign" ) == "<=" )
367+ .then (pl .col ("rhs" ) >= 0 )
368+ .when (pl .col ("sign" ) == "<=" )
369+ .then (pl .col ("rhs" ) <= 0 )
370+ .otherwise (pl .lit (False ))
371+ )
372+
373+ # Ensure each constraint has both coefficient terms and a valid rhs
365374 analysis = df .group_by ("labels" ).agg (
366375 [
367376 pl .col ("coeffs" ).is_not_null ().sum ().alias ("coeff_rows" ),
368- pl .col ("sign" ).is_not_null ().sum ().alias ("rhs_rows" ),
377+ (pl .col ("rhs" ).is_not_null () & ~ rhs_unbounded )
378+ .any ()
379+ .alias ("has_rhs" ),
369380 ]
370381 )
371382
372- valid = analysis .filter (
373- (pl .col ("coeff_rows" ) > 0 ) & (pl .col ("rhs_rows" ) > 0 )
374- )
383+ valid = analysis .filter ((pl .col ("coeff_rows" ) > 0 ) & pl .col ("has_rhs" ))
375384
376385 if valid .height == 0 :
377386 continue
You can’t perform that action at this time.
0 commit comments