1
1
"""test to_datetime"""
2
2
3
3
import calendar
4
+ import locale
4
5
from collections import deque
5
6
from datetime import (
6
7
date ,
9
10
timezone ,
10
11
)
11
12
from decimal import Decimal
12
- import locale
13
13
import zoneinfo
14
14
15
- from dateutil .parser import parse
16
15
import numpy as np
16
+ import pandas as pd
17
17
import pytest
18
+ from dateutil .parser import parse
18
19
19
20
from pandas ._libs import tslib
20
21
from pandas ._libs .tslibs import (
29
30
import pandas .util ._test_decorators as td
30
31
31
32
from pandas .core .dtypes .common import is_datetime64_ns_dtype
32
-
33
- import pandas as pd
34
33
from pandas import (
35
34
DataFrame ,
36
35
DatetimeIndex ,
@@ -3689,3 +3688,22 @@ def test_to_datetime_wrapped_datetime64_ps():
3689
3688
["1970-01-01 00:00:01.901901901" ], dtype = "datetime64[ns]" , freq = None
3690
3689
)
3691
3690
tm .assert_index_equal (result , expected )
3691
+
3692
+
3693
+ def test_to_datetime_scalar_out_of_bounds ():
3694
+ """Ensure pd.to_datetime raises an error for out-of-bounds scalar values."""
3695
+ uint64_max = np .iinfo ("uint64" ).max
3696
+
3697
+ # Expect an OverflowError when passing uint64_max as a scalar
3698
+ with pytest .raises (OutOfBoundsDatetime ):
3699
+ pd .to_datetime (uint64_max , unit = "ns" )
3700
+
3701
+ # Expect the same behavior when passing it as a list
3702
+ with pytest .raises (OutOfBoundsDatetime ):
3703
+ pd .to_datetime ([uint64_max ], unit = "ns" )
3704
+
3705
+ # Test a valid value (should not raise an error)
3706
+ valid_timestamp = 1_700_000_000_000_000_000 # A reasonable nanosecond timestamp
3707
+ result = pd .to_datetime (valid_timestamp , unit = "ns" )
3708
+ assert isinstance (result , pd .Timestamp )
3709
+
0 commit comments