Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thisandthatuser opened this issue Aug 29, 2024 · 0 comments · May be fixed by #173
Open

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

thisandthatuser opened this issue Aug 29, 2024 · 0 comments · May be fixed by #173
Labels
bug Something isn't working

Comments

@thisandthatuser
Copy link
Contributor

thisandthatuser commented Aug 29, 2024

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

@thisandthatuser thisandthatuser added the bug Something isn't working label Aug 29, 2024
@thisandthatuser thisandthatuser linked a pull request Aug 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant