From d04c9dda00ad11749df915e9399b17a66c43f5db Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 20 Feb 2024 10:14:10 -0800 Subject: [PATCH 1/3] TST: Allow test_dti_constructor_with_non_nano_now_today to be flaky --- .../tests/indexes/datetimes/test_constructors.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pandas/tests/indexes/datetimes/test_constructors.py b/pandas/tests/indexes/datetimes/test_constructors.py index 0756d490cd4fa..dfae4270f7804 100644 --- a/pandas/tests/indexes/datetimes/test_constructors.py +++ b/pandas/tests/indexes/datetimes/test_constructors.py @@ -1031,23 +1031,23 @@ def test_dti_constructor_with_non_nano_dtype(self, tz): result2 = DatetimeIndex(np.array(vals, dtype=object), dtype=dtype) tm.assert_index_equal(result2, expected) - def test_dti_constructor_with_non_nano_now_today(self): + def test_dti_constructor_with_non_nano_now_today(self, request): # GH#55756 now = Timestamp.now() today = Timestamp.today() result = DatetimeIndex(["now", "today"], dtype="M8[s]") assert result.dtype == "M8[s]" + diff0 = result[0] - now.as_unit("s") + diff1 = result[1] - today.as_unit("s") + assert diff1 >= pd.Timedelta(0), f"The difference is {diff0}" + assert diff0 >= pd.Timedelta(0), f"The difference is {diff0}" + # result may not exactly match [now, today] so we'll test it up to a tolerance. # (it *may* match exactly due to rounding) + request.applymarker(pytest.mark.xfail(strict=False)) tolerance = pd.Timedelta(seconds=1) - - diff0 = result[0] - now.as_unit("s") - assert diff0 >= pd.Timedelta(0), f"The difference is {diff0}" assert diff0 < tolerance, f"The difference is {diff0}" - - diff1 = result[1] - today.as_unit("s") - assert diff1 >= pd.Timedelta(0), f"The difference is {diff0}" assert diff1 < tolerance, f"The difference is {diff0}" def test_dti_constructor_object_float_matches_float_dtype(self): From 2211e8edded8899fae804cd443a1b8531476db67 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 20 Feb 2024 10:16:00 -0800 Subject: [PATCH 2/3] Add GH reference --- pandas/tests/indexes/datetimes/test_constructors.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/indexes/datetimes/test_constructors.py b/pandas/tests/indexes/datetimes/test_constructors.py index dfae4270f7804..d744bafca5d4c 100644 --- a/pandas/tests/indexes/datetimes/test_constructors.py +++ b/pandas/tests/indexes/datetimes/test_constructors.py @@ -1045,6 +1045,7 @@ def test_dti_constructor_with_non_nano_now_today(self, request): # result may not exactly match [now, today] so we'll test it up to a tolerance. # (it *may* match exactly due to rounding) + # GH 57535 request.applymarker(pytest.mark.xfail(strict=False)) tolerance = pd.Timedelta(seconds=1) assert diff0 < tolerance, f"The difference is {diff0}" From 5ba2f1cf60624c0adf31ecd0cbb140e418d1a127 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 20 Feb 2024 10:16:53 -0800 Subject: [PATCH 3/3] Add reason --- pandas/tests/indexes/datetimes/test_constructors.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexes/datetimes/test_constructors.py b/pandas/tests/indexes/datetimes/test_constructors.py index d744bafca5d4c..009723fc42360 100644 --- a/pandas/tests/indexes/datetimes/test_constructors.py +++ b/pandas/tests/indexes/datetimes/test_constructors.py @@ -1046,7 +1046,11 @@ def test_dti_constructor_with_non_nano_now_today(self, request): # result may not exactly match [now, today] so we'll test it up to a tolerance. # (it *may* match exactly due to rounding) # GH 57535 - request.applymarker(pytest.mark.xfail(strict=False)) + request.applymarker( + pytest.mark.xfail( + reason="result may not exactly match [now, today]", strict=False + ) + ) tolerance = pd.Timedelta(seconds=1) assert diff0 < tolerance, f"The difference is {diff0}" assert diff1 < tolerance, f"The difference is {diff0}"