Skip to content

Commit ca826d8

Browse files
committed
add hypothesis and negative test
1 parent a1d90d3 commit ca826d8

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

pandas/tests/scalar/timestamp/test_timestamp.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
tzlocal,
1515
tzutc,
1616
)
17+
from hypothesis import given
1718
import numpy as np
1819
import pytest
1920
import pytz
@@ -36,6 +37,7 @@
3637
Timestamp,
3738
)
3839
import pandas._testing as tm
40+
from pandas._testing._hypothesis import DATETIME_IN_PD_TIMESTAMP_RANGE_NO_TZ
3941

4042
from pandas.tseries import offsets
4143
from pandas.tseries.frequencies import to_offset
@@ -224,14 +226,29 @@ def test_resolution(self):
224226
assert dt.as_unit("s").resolution == Timedelta(seconds=1)
225227

226228
@pytest.mark.parametrize(
227-
"date_string,expected",
228-
[("0000-2-29", 1), ("0000-3-1", 2), ("1582-10-14", 3), ("1582-10-15", 4)],
229+
"date_string, expected_true, expected_false",
230+
[
231+
("0000-2-29", 1, 2),
232+
("0000-3-1", 2, 3),
233+
("1582-10-14", 3, 4),
234+
("1582-10-15", 4, 5),
235+
("1752-01-01", 5, 6),
236+
("2023-06-18", 6, 0),
237+
],
229238
)
230-
def test_dow_historic(self, date_string, expected):
239+
def test_dow_historic(self, date_string, expected_true, expected_false):
231240
# GH 53738
232241
dt = Timestamp(date_string)
233242
dow = dt.weekday()
234-
assert dow == expected
243+
assert dow == expected_true
244+
assert not dow == expected_false
245+
246+
@given(DATETIME_IN_PD_TIMESTAMP_RANGE_NO_TZ)
247+
def test_dow_sanity(self, dt):
248+
# GH 53738
249+
expected = dt.weekday()
250+
result = datetime(dt.year, dt.month, dt.day).weekday()
251+
assert result == expected
235252

236253

237254
class TestTimestamp:

0 commit comments

Comments
 (0)