7
7
8
8
import numpy as np
9
9
10
- from pandas ._libs import lib , tslib , tslibs
10
+ from pandas ._libs import lib , tslib
11
11
from pandas ._libs .tslibs import (
12
12
NaT ,
13
13
OutOfBoundsDatetime ,
14
14
Period ,
15
15
Timedelta ,
16
16
Timestamp ,
17
+ conversion ,
17
18
iNaT ,
18
19
ints_to_pydatetime ,
20
+ ints_to_pytimedelta ,
19
21
)
20
22
from pandas ._libs .tslibs .timezones import tz_compare
21
23
from pandas ._typing import ArrayLike , Dtype , DtypeObj
@@ -552,7 +554,7 @@ def maybe_promote(dtype, fill_value=np.nan):
552
554
dtype = np .dtype (np .object_ )
553
555
else :
554
556
try :
555
- fill_value = tslibs . Timestamp (fill_value ).to_datetime64 ()
557
+ fill_value = Timestamp (fill_value ).to_datetime64 ()
556
558
except (TypeError , ValueError ):
557
559
dtype = np .dtype (np .object_ )
558
560
elif issubclass (dtype .type , np .timedelta64 ):
@@ -565,7 +567,7 @@ def maybe_promote(dtype, fill_value=np.nan):
565
567
dtype = np .dtype (np .object_ )
566
568
else :
567
569
try :
568
- fv = tslibs . Timedelta (fill_value )
570
+ fv = Timedelta (fill_value )
569
571
except ValueError :
570
572
dtype = np .dtype (np .object_ )
571
573
else :
@@ -738,8 +740,8 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> Tuple[DtypeObj,
738
740
dtype = np .dtype (object )
739
741
740
742
elif isinstance (val , (np .datetime64 , datetime )):
741
- val = tslibs . Timestamp (val )
742
- if val is tslibs . NaT or val .tz is None :
743
+ val = Timestamp (val )
744
+ if val is NaT or val .tz is None :
743
745
dtype = np .dtype ("M8[ns]" )
744
746
else :
745
747
if pandas_dtype :
@@ -750,7 +752,7 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> Tuple[DtypeObj,
750
752
val = val .value
751
753
752
754
elif isinstance (val , (np .timedelta64 , timedelta )):
753
- val = tslibs . Timedelta (val ).value
755
+ val = Timedelta (val ).value
754
756
dtype = np .dtype ("m8[ns]" )
755
757
756
758
elif is_bool (val ):
@@ -941,9 +943,9 @@ def conv(r, dtype):
941
943
if np .any (isna (r )):
942
944
pass
943
945
elif dtype == DT64NS_DTYPE :
944
- r = tslibs . Timestamp (r )
946
+ r = Timestamp (r )
945
947
elif dtype == TD64NS_DTYPE :
946
- r = tslibs . Timedelta (r )
948
+ r = Timedelta (r )
947
949
elif dtype == np .bool_ :
948
950
# messy. non 0/1 integers do not get converted.
949
951
if is_integer (r ) and r not in [0 , 1 ]:
@@ -1006,7 +1008,7 @@ def astype_nansafe(arr, dtype, copy: bool = True, skipna: bool = False):
1006
1008
1007
1009
elif is_timedelta64_dtype (arr ):
1008
1010
if is_object_dtype (dtype ):
1009
- return tslibs . ints_to_pytimedelta (arr .view (np .int64 ))
1011
+ return ints_to_pytimedelta (arr .view (np .int64 ))
1010
1012
elif dtype == np .int64 :
1011
1013
if isna (arr ).any ():
1012
1014
raise ValueError ("Cannot convert NaT values to integer" )
@@ -1317,8 +1319,6 @@ def try_datetime(v):
1317
1319
# we might have a sequence of the same-datetimes with tz's
1318
1320
# if so coerce to a DatetimeIndex; if they are not the same,
1319
1321
# then these stay as object dtype, xref GH19671
1320
- from pandas ._libs .tslibs import conversion
1321
-
1322
1322
from pandas import DatetimeIndex
1323
1323
1324
1324
try :
@@ -1492,7 +1492,7 @@ def maybe_cast_to_datetime(value, dtype, errors: str = "raise"):
1492
1492
dtype = value .dtype
1493
1493
1494
1494
if dtype .kind == "M" and dtype != DT64NS_DTYPE :
1495
- value = tslibs . conversion .ensure_datetime64ns (value )
1495
+ value = conversion .ensure_datetime64ns (value )
1496
1496
1497
1497
elif dtype .kind == "m" and dtype != TD64NS_DTYPE :
1498
1498
value = to_timedelta (value )
0 commit comments