Skip to content

6.2.0 no longer handles values that are numpy.float64 in constraint comparisons being negated #1218

Closed

Description

@jnh277

Describe the bug

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

  import numpy as np
  from pyscipopt import Model

  model = 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.float64
  value = np.float64(5.0)

  # This raises AttributeError on pyscipopt 6.2.0
  model.addCons(-value <= x - y + z, name="test")

  Full traceback:
  Traceback (most recent call last):
    File "test.py", line 12, in <module>
      model.addCons(-value <= x - y + z, name="test")
    File "src/pyscipopt/expr.pxi", line 211, in pyscipopt.scip.ExprLike.__array_ufunc__
    File "src/pyscipopt/matrix.pxi", line 63, in pyscipopt.scip.MatrixExpr.__array_ufunc__
  AttributeError: 'pyscipopt.scip.ExprCons' object has no attribute '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.

Activity

  1. 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
  2. Joao-Dionisio commented on May 12, 2026

    @Joao-Dionisio
    Member

    Thank you and apologies @jnh277 ! @Zeroto521 , can you please take a look?

  3. Zeroto521 commented on May 12, 2026

    @Zeroto521
    Contributor

    Fixed by #1219

  4. Joao-Dionisio commented on May 16, 2026

    @Joao-Dionisio
    Member

    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.

  5. jnh277 commented on May 17, 2026

    @jnh277
    Author

    Great! thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions