Skip to content

Commit 8ebc910

Browse files
TST: don't try to use non-integer years (see pandas-dev#50301)
1 parent 400bb22 commit 8ebc910

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

pandas/tests/tools/test_to_datetime.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1936,24 +1936,24 @@ def test_to_timestamp_unit_coerce(self, bad_val):
19361936
tm.assert_index_equal(result, expected)
19371937

19381938
def test_float_to_datetime_raise_near_bounds(self):
1939-
msg = "cannot convert input with unit 'Y'"
1940-
oneyear_in_ns = 1e9 * 60 * 60 * 24 * 365.2425
1941-
tsmax_in_years = 2**63 / oneyear_in_ns # 2**63 ns, in years
1939+
msg = "cannot convert input with unit 'D'"
1940+
oneday_in_ns = 1e9 * 60 * 60 * 24
1941+
tsmax_in_days = 2**63 / oneday_in_ns # 2**63 ns, in days
19421942
# just in bounds
19431943
should_succeed = Series(
1944-
[0, tsmax_in_years - 0.05, -tsmax_in_years + 0.05], dtype=float
1944+
[0, tsmax_in_days - 0.05, -tsmax_in_days + 0.05], dtype=float
19451945
)
1946-
expected = (should_succeed * oneyear_in_ns).astype(np.int64)
1946+
expected = (should_succeed * oneday_in_ns).astype(np.int64)
19471947
for error_mode in ["raise", "coerce", "ignore"]:
1948-
result1 = to_datetime(should_succeed, unit="Y", errors=error_mode)
1948+
result1 = to_datetime(should_succeed, unit="D", errors=error_mode)
19491949
tm.assert_almost_equal(result1.astype(np.int64), expected, rtol=1e-10)
19501950
# just out of bounds
1951-
should_fail1 = Series([0, tsmax_in_years + 0.05], dtype=float)
1952-
should_fail2 = Series([0, -tsmax_in_years - 0.05], dtype=float)
1951+
should_fail1 = Series([0, tsmax_in_days + 0.05], dtype=float)
1952+
should_fail2 = Series([0, -tsmax_in_days - 0.05], dtype=float)
19531953
with pytest.raises(OutOfBoundsDatetime, match=msg):
1954-
to_datetime(should_fail1, unit="Y", errors="raise")
1954+
to_datetime(should_fail1, unit="D", errors="raise")
19551955
with pytest.raises(OutOfBoundsDatetime, match=msg):
1956-
to_datetime(should_fail2, unit="Y", errors="raise")
1956+
to_datetime(should_fail2, unit="D", errors="raise")
19571957

19581958

19591959
class TestToDatetimeDataFrame:

0 commit comments

Comments
 (0)