Skip to content

[BUG] Tests are failing because of changes introduced with numpy 2.x #172

@thisandthatuser

Description

@thisandthatuser

Describe the bug

Tests, specifically a couple of them contained in a docstring from the _py_algorithms.py file, are failing due to the representation numbers.

Numpy 2.x introduced changes in the representation of scalars. Therefore, instead of having a clear output like you would without numpy, the output now also includes 'np.float64', for example.

The most logical solution is to update the representation of those scalars. Forcing the tests to use numpy < 2.x should also work as a temporary fix.

To Reproduce

The code block below should produce no errors if numpy < 2.x is used but fail if 2.x is used.

# numpy < 2.x
import pygmo as pg
import numpy as np
prob = pg.problem(pg.rosenbrock(10))
pop = pg.population(prob=prob, size=1, seed=0)
pop.champion_f[0]
# tests
assert pop.champion_f[0] == 929975.7994682974
assert repr(pop.champion_f[0]) == repr(929975.7994682974)
assert pop.champion_f[0] == np.float64(929975.7994682974)
assert repr(pop.champion_f[0]) == repr(np.float64(929975.7994682974))

Expected behavior

The tests should pass since the scalars are correct.

Screenshots

From the CI/CD run of #167

Screenshot from 2024-08-29 11-12-16

Environment (please complete the following information):

  • OS: Ubuntu 22.04
  • Installation method: compiled from source
  • Version: 2.19.6

Additional context

The relevant numpy changes are described here: https://numpy.org/devdocs/release/2.0.0-notes.html#representation-of-numpy-scalars-changed

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions