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

tests use equality to compare floating point numbers #4158

Open
drew-parsons opened this issue Nov 8, 2024 · 1 comment · May be fixed by #4159
Open

tests use equality to compare floating point numbers #4158

drew-parsons opened this issue Nov 8, 2024 · 1 comment · May be fixed by #4159

Comments

@drew-parsons
Copy link
Contributor

Floating point numbers (angles) are compared in transformation tests at

assert transformed_cubic.lattice.angles == transformed_orthorhombic.lattice.angles

Using equality to compare floating point numbers inevitably fails
e.g. https://buildd.debian.org/status/fetch.php?pkg=pymatgen&arch=amd64&ver=2024.10.29%2Bdfsg1-1&stamp=1731061592&raw=0

        # make sure that the orthorhombic supercell is different from the cubic cell
        assert not np.array_equal(
            supercell_generator_cubic.transformation_matrix,
            supercell_generator_orthorhombic.transformation_matrix,
        )
        assert transformed_orthorhombic.lattice.abc != transformed_cubic.lattice.abc
        # only angels are expected to be the same because of force_90_degrees = True
>       assert transformed_cubic.lattice.angles == transformed_orthorhombic.lattice.angles
E       assert (89.999970160...0000000086139) == (89.999970160...0000000086142)
E         
E         At index 2 diff: 90.00000000086139 != 90.00000000086142
E         Use -v to get more diff

/<<PKGBUILDDIR>>/.pybuild/test_python3.12/tests/transformations/test_advanced_transformations.py:840: AssertionError

Floating point comparison needs to be used instead

assert_allclose(transformed_cubic.lattice.angles, lattice.angles)
@DanielYang59
Copy link
Contributor

Thanks for reporting, would fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants