Skip to content

Commit 7aa19f0

Browse files
authored
TST: Use hypothesis for test_round_sanity (#44550)
1 parent f0e75f3 commit 7aa19f0

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

pandas/tests/scalar/timedelta/test_timedelta.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
""" test the scalar Timedelta """
22
from datetime import timedelta
33

4+
from hypothesis import (
5+
given,
6+
strategies as st,
7+
)
48
import numpy as np
59
import pytest
610

@@ -394,12 +398,12 @@ def test_round_implementation_bounds(self):
394398
with pytest.raises(OverflowError, match=msg):
395399
Timedelta.max.ceil("s")
396400

397-
@pytest.mark.parametrize("n", range(100))
401+
@given(val=st.integers(min_value=iNaT + 1, max_value=lib.i8max))
398402
@pytest.mark.parametrize(
399403
"method", [Timedelta.round, Timedelta.floor, Timedelta.ceil]
400404
)
401-
def test_round_sanity(self, method, n, request):
402-
val = np.random.randint(iNaT + 1, lib.i8max, dtype=np.int64)
405+
def test_round_sanity(self, val, method):
406+
val = np.int64(val)
403407
td = Timedelta(val)
404408

405409
assert method(td, "ns") == td

pandas/tests/scalar/timestamp/test_unary_ops.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from datetime import datetime
22

33
from dateutil.tz import gettz
4+
from hypothesis import (
5+
given,
6+
strategies as st,
7+
)
48
import numpy as np
59
import pytest
610
import pytz
@@ -276,12 +280,12 @@ def test_round_implementation_bounds(self):
276280
with pytest.raises(OverflowError, match=msg):
277281
Timestamp.max.ceil("s")
278282

279-
@pytest.mark.parametrize("n", range(100))
283+
@given(val=st.integers(iNaT + 1, lib.i8max))
280284
@pytest.mark.parametrize(
281285
"method", [Timestamp.round, Timestamp.floor, Timestamp.ceil]
282286
)
283-
def test_round_sanity(self, method, n):
284-
val = np.random.randint(iNaT + 1, lib.i8max, dtype=np.int64)
287+
def test_round_sanity(self, val, method):
288+
val = np.int64(val)
285289
ts = Timestamp(val)
286290

287291
def checker(res, ts, nanos):

0 commit comments

Comments
 (0)