From 52e11892665091b0f28c76acb56e9c7f63f09814 Mon Sep 17 00:00:00 2001 From: Alexandra Udaltsova <43303448+AUdaltsova@users.noreply.github.com> Date: Tue, 6 Aug 2024 13:30:29 +0100 Subject: [PATCH] Change tolerance of test in test_datetime_features.py --- .../numpy_batch/test_datetime_features.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/transform/numpy_batch/test_datetime_features.py b/tests/transform/numpy_batch/test_datetime_features.py index cbdce16d..47a9e3fa 100644 --- a/tests/transform/numpy_batch/test_datetime_features.py +++ b/tests/transform/numpy_batch/test_datetime_features.py @@ -25,8 +25,12 @@ def test_get_date_time_in_pi(): times = np.array([datetime.fromisoformat(time) for time in times], dtype="datetime64[s]") date_in_pi, time_in_pi = _get_date_time_in_pi(times) - - assert np.isclose(np.cos(time_in_pi), np.cos(expected_times_in_pi), atol=1e-04).all() - assert np.isclose(np.sin(time_in_pi), np.sin(expected_times_in_pi), atol=1e-04).all() - assert np.isclose(np.cos(date_in_pi), np.cos(expected_times_in_pi), atol=0.01).all() - assert np.isclose(np.sin(date_in_pi), np.sin(expected_times_in_pi), atol=0.02).all() + + # Note on precision: times are compared with tolerance equivalent to 1 second, + # dates are compared with tolerance equivalent to 5 minutes + # None of the data we use has a higher time resolution, so this is a good test of + # whether not accounting for leap years breaks things + assert np.isclose(np.cos(time_in_pi), np.cos(expected_times_in_pi), atol=7.3e-05).all() + assert np.isclose(np.sin(time_in_pi), np.sin(expected_times_in_pi), atol=7.3e-05).all() + assert np.isclose(np.cos(date_in_pi), np.cos(expected_times_in_pi), atol=0.02182).all() + assert np.isclose(np.sin(date_in_pi), np.sin(expected_times_in_pi), atol=0.02182).all()