pyemd icon indicating copy to clipboard operation
pyemd copied to clipboard

Numpy 2.1: Changed value for emd_samples -- unit tests fail

Open bnavigator opened this issue 11 months ago • 0 comments

Since we upgraded to numpy 2.1, the packaging of pyemd fails:

[   40s] ______________________________ test_emd_samples_2 ______________________________
[   40s] 
[   40s]     def test_emd_samples_2():
[   40s]         first_array = [1]
[   40s]         second_array = [2]
[   40s] >       emd_assert(emd_samples(first_array, second_array), 0.5)
[   40s] 
[   40s] test_pyemd.py:335: 
[   40s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   40s] 
[   40s] got = 0.0, expected = 0.5
[   40s] 
[   40s]     def emd_assert(got, expected):
[   40s] >       assert round(got, EMD_PRECISION) == expected
[   40s] E       assert 0.0 == 0.5
[   40s] E        +  where 0.0 = round(0.0, 5)
[   40s] 
[   40s] test_pyemd.py:17: AssertionError
[   40s] ______________________________ test_emd_samples_3 ______________________________
[   40s] 
[   40s]     def test_emd_samples_3():
[   40s]         first_array = [1, 1, 1, 2, 3]
[   40s]         second_array = [1, 2, 2, 2, 3]
[   40s] >       emd_assert(emd_samples(first_array, second_array), 0.32)
[   40s] 
[   40s] test_pyemd.py:341: 
[   40s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   40s] 
[   40s] got = 0.4, expected = 0.32
[   40s] 
[   40s]     def emd_assert(got, expected):
[   40s] >       assert round(got, EMD_PRECISION) == expected
[   40s] E       assert 0.4 == 0.32
[   40s] E        +  where 0.4 = round(0.4, 5)

Steps to reproduce:

Compile with numpy 2 (2.0 or 2.1 does not matter)

python3 -m venv pyemd-np2
sed -i 's/oldest-supported-numpy/numpy>=2/' pyemd/pyproject.toml
pyemd-np2/bin/python3 -m pip -v install './pyemd/'

Execute with numpy 2.1:

Python 3.11.10 (main, Sep 09 2024, 17:03:08) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'2.1.3'
>>> from pyemd import emd_samples
>>> emd_samples([1], [2])
0.0

Execute with numpy 2.0:

pyemd-np2/bin/python3 -m pip install 'numpy<2.1'
Python 3.11.10 (main, Sep 09 2024, 17:03:08) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'2.0.2'
>>> from pyemd import emd_samples
>>> emd_samples([1], [2])
0.5

bnavigator avatar Nov 15 '24 18:11 bnavigator