From 3e8998a6f4e66222784167ba2f23cc888f588653 Mon Sep 17 00:00:00 2001 From: Santiago Soler Date: Thu, 7 Mar 2024 15:53:35 -0800 Subject: [PATCH 1/2] Fix Python tests to work with latest Numpy version Modify how the potential and acceleration are retrieved from the solution returned by `evaluate()` and `GravityEvaluable` in tests so the code can run with latest Numpy versions. The previous tests were trying to generate an array from ragged tuples, which is no longer supported by Numpy. Also, modify the `assert np.testing.assert_almost_equal() is None` lines since the Numpy testing functions always return `None`. --- test/python/test_polyhedral_gravity.py | 30 +++++++++++--------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/test/python/test_polyhedral_gravity.py b/test/python/test_polyhedral_gravity.py index 6f9fa8d..d7814bf 100644 --- a/test/python/test_polyhedral_gravity.py +++ b/test/python/test_polyhedral_gravity.py @@ -65,12 +65,10 @@ def test_polyhedral_gravity( computation_points=points, parallel=True ) - sol = np.array([np.array(x) for x in sol]) - actual_potential = sol[:, 0].flatten() - assert np.testing.assert_array_almost_equal(actual_potential, expected_potential) is None - - actual_acceleration = np.array([np.array(x) for x in sol[:, 1]]) - assert np.testing.assert_array_almost_equal(actual_acceleration, expected_acceleration) is None + potential = np.array([result[0] for result in sol]) + acceleration = np.array([result[1] for result in sol]) + np.testing.assert_array_almost_equal(potential, expected_potential) + np.testing.assert_array_almost_equal(acceleration, expected_acceleration) @pytest.mark.parametrize( @@ -92,12 +90,10 @@ def test_polyhedral_gravity_evaluable( computation_points=points, parallel=True ) - sol = np.array([np.array(x) for x in sol]) - actual_potential = sol[:, 0].flatten() - assert np.testing.assert_array_almost_equal(actual_potential, expected_potential) is None - - actual_acceleration = np.array([np.array(x) for x in sol[:, 1]]) - assert np.testing.assert_array_almost_equal(actual_acceleration, expected_acceleration) is None + potential = np.array([result[0] for result in sol]) + acceleration = np.array([result[1] for result in sol]) + np.testing.assert_array_almost_equal(potential, expected_potential) + np.testing.assert_array_almost_equal(acceleration, expected_acceleration) @pytest.mark.parametrize( @@ -128,9 +124,7 @@ def test_polyhedral_evaluable_pickle( computation_points=points, parallel=True ) - sol = np.array([np.array(x) for x in sol]) - actual_potential = sol[:, 0].flatten() - assert np.testing.assert_array_almost_equal(actual_potential, expected_potential) is None - - actual_acceleration = np.array([np.array(x) for x in sol[:, 1]]) - assert np.testing.assert_array_almost_equal(actual_acceleration, expected_acceleration) is None + potential = np.array([result[0] for result in sol]) + acceleration = np.array([result[1] for result in sol]) + np.testing.assert_array_almost_equal(potential, expected_potential) + np.testing.assert_array_almost_equal(acceleration, expected_acceleration) From 86fd2f41990ed86e92fd81ed593af74dc394ac18 Mon Sep 17 00:00:00 2001 From: Santiago Soler Date: Thu, 7 Mar 2024 15:56:56 -0800 Subject: [PATCH 2/2] Unpin Numpy version in environment.yml --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index 6fcf810..e8087c0 100644 --- a/environment.yml +++ b/environment.yml @@ -2,6 +2,6 @@ name: polyhedral-gravity-env channels: - conda-forge dependencies: - - numpy==1.23.4 + - numpy - pytest - pytest-xdist \ No newline at end of file