You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
6.2.0 no longer handles values that are numpy.float64 in constraint comparisons being negated #1218
When using pyscipopt 6.2.0 with numpy 2.x, passing a numpy.float64 value to a constraint comparison raises an AttributeError. This occurs when a numpy scalar is negated and used in a comparison with pyscipopt expression variables.
The error is:
AttributeError: 'pyscipopt.scip.ExprCons' object has no attribute 'view'
This worked correctly in pyscipopt 6.1.0.
To Reproduce
importnumpyasnpfrompyscipoptimportModelmodel=Model()
x=model.addVar(vtype="C", lb=None, ub=None, name="x")
y=model.addVar(vtype="C", lb=None, ub=None, name="y")
z=model.addVar(vtype="C", lb=0, name="z")
# This value is a numpy.float64value=np.float64(5.0)
# This raises AttributeError on pyscipopt 6.2.0model.addCons(-value<=x-y+z, name="test")
Fulltraceback:
Traceback (mostrecentcalllast):
File"test.py", line12, in<module>model.addCons(-value<=x-y+z, name="test")
File"src/pyscipopt/expr.pxi", line211, inpyscipopt.scip.ExprLike.__array_ufunc__File"src/pyscipopt/matrix.pxi", line63, inpyscipopt.scip.MatrixExpr.__array_ufunc__AttributeError: 'pyscipopt.scip.ExprCons'objecthasnoattribute'view'
Expected behavior
The constraint should be added to the model without error, as it does in pyscipopt 6.1.0.
Workaround
Converting numpy floats to native Python floats before using in constraints works:
model.addCons(-float(value) <= x - y + z, name="test") # Works
System
OS: macOS (Darwin 25.3.0)
Python: 3.12.12
pyscipopt: 6.2.0
SCIP version: 10.0
numpy: 2.4.4
Installed via: uv pip install pyscipopt
Additional context
This issue appears to be related to the array_ufunc implementation in expr.pxi and matrix.pxi. When numpy negates a numpy.float64 scalar and then compares it with a pyscipopt expression, numpy's array protocol calls array_ufunc on the pyscipopt ExprCons object, which attempts to call .view() on it, but ExprCons doesn't have that attribute.
The issue does not occur with native Python floats, only with numpy scalar types.
changed the title [-]6.2.0 no longer handles values that are numpy.float64 in constraint comparisons[/-][+]6.2.0 no longer handles values that are numpy.float64 in constraint comparisons being negated[/+]on May 12, 2026
Activity
[-]6.2.0 no longer handles values that are numpy.float64 in constraint comparisons[/-][+]6.2.0 no longer handles values that are numpy.float64 in constraint comparisons being negated[/+]Joao-Dionisio commentedon May 12, 2026
Thank you and apologies @jnh277 ! @Zeroto521 , can you please take a look?
Add test for np.float64 comparisons with Expr
Zeroto521 commentedon May 12, 2026
Fixed by #1219
BUG: `Expr.__array_ufunc__` can't handle 0-dim array (#1219)
Joao-Dionisio commentedon May 16, 2026
Hey @jnh277 , the fix is already in master. I'll do a bugfix release over the weekend.
EDIT: The wheels are building, should only take a couple hours.
jnh277 commentedon May 17, 2026
Great! thank you