Skip to content

TST: Allow test_dti_constructor_with_non_nano_now_today to be flaky #57535

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

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pandas/tests/indexes/datetimes/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,23 +1031,28 @@ 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)
# GH 57535
request.applymarker(
pytest.mark.xfail(
reason="result may not exactly match [now, today]", 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):
Expand Down