Skip to content

Commit 6c6c143

Browse files
committed
Add test for lower bound
1 parent cb710ee commit 6c6c143

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pandas/core/tools/datetimes.py

+4
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,10 @@ def _array_strptime_with_fallback(
482482
def _to_datetime_with_unit(arg, unit, name, utc: bool, errors: str) -> DatetimeIndex:
483483
"""
484484
to_datetime specialized to the case where a 'unit' is passed.
485+
486+
Note: This function currently treats values at the upper bound differently from values at the lower bound.
487+
For upper bound, it raises OutOfBoundsDatetime.
488+
For lower bound, it returns NaT.
485489
"""
486490
arg = extract_array(arg, extract_numpy=True)
487491
# Fix GH#60677

pandas/tests/tools/test_to_datetime.py

+9
Original file line numberDiff line numberDiff line change
@@ -3694,6 +3694,7 @@ def test_to_datetime_wrapped_datetime64_ps():
36943694
def test_to_datetime_scalar_out_of_bounds():
36953695
"""Ensure pd.to_datetime raises an error for out-of-bounds scalar values."""
36963696
uint64_max = np.iinfo("uint64").max
3697+
int64_min = np.iinfo("int64").min
36973698

36983699
# Expect an OverflowError when passing uint64_max as a scalar
36993700
with pytest.raises(OutOfBoundsDatetime):
@@ -3703,6 +3704,14 @@ def test_to_datetime_scalar_out_of_bounds():
37033704
with pytest.raises(OutOfBoundsDatetime):
37043705
to_datetime([uint64_max], unit="ns")
37053706

3707+
# Expect NAT when passing int64_min as a scalar
3708+
value = to_datetime(int64_min, unit="ns")
3709+
assert value is NaT
3710+
3711+
# Expect the same behavior when passing it as a list
3712+
value = to_datetime([int64_min], unit="ns")
3713+
assert value[0] is NaT
3714+
37063715
# Test a valid value (should not raise an error)
37073716
valid_timestamp = 1_700_000_000_000_000_000 # A reasonable nanosecond timestamp
37083717
result = to_datetime(valid_timestamp, unit="ns")

0 commit comments

Comments
 (0)