27
27
astype_overflowsafe ,
28
28
fields ,
29
29
get_resolution ,
30
- get_supported_reso ,
30
+ get_supported_dtype ,
31
31
get_unit_from_dtype ,
32
32
ints_to_pydatetime ,
33
33
is_date_array_normalized ,
34
- is_supported_unit ,
34
+ is_supported_dtype ,
35
35
is_unitless ,
36
36
normalize_i8_timestamps ,
37
- npy_unit_to_abbrev ,
38
37
timezones ,
39
38
to_offset ,
40
39
tz_convert_from_utc ,
@@ -712,7 +711,7 @@ def astype(self, dtype, copy: bool = True):
712
711
self .tz is None
713
712
and lib .is_np_dtype (dtype , "M" )
714
713
and not is_unitless (dtype )
715
- and is_supported_unit ( get_unit_from_dtype ( dtype ) )
714
+ and is_supported_dtype ( dtype )
716
715
):
717
716
# unit conversion e.g. datetime64[s]
718
717
res_values = astype_overflowsafe (self ._ndarray , dtype , copy = True )
@@ -2307,7 +2306,7 @@ def _sequence_to_dt64(
2307
2306
assert isinstance (result , np .ndarray ), type (result )
2308
2307
assert result .dtype .kind == "M"
2309
2308
assert result .dtype != "M8"
2310
- assert is_supported_unit ( get_unit_from_dtype ( result .dtype ) )
2309
+ assert is_supported_dtype ( result .dtype )
2311
2310
return result , tz
2312
2311
2313
2312
@@ -2321,14 +2320,10 @@ def _construct_from_dt64_naive(
2321
2320
# lib.is_np_dtype(data.dtype)
2322
2321
2323
2322
new_dtype = data .dtype
2324
- data_unit = get_unit_from_dtype (new_dtype )
2325
- if not is_supported_unit (data_unit ):
2323
+ if not is_supported_dtype (new_dtype ):
2326
2324
# Cast to the nearest supported unit, generally "s"
2327
- new_reso = get_supported_reso (data_unit )
2328
- new_unit = npy_unit_to_abbrev (new_reso )
2329
- new_dtype = np .dtype (f"M8[{ new_unit } ]" )
2325
+ new_dtype = get_supported_dtype (new_dtype )
2330
2326
data = astype_overflowsafe (data , dtype = new_dtype , copy = False )
2331
- data_unit = get_unit_from_dtype (new_dtype )
2332
2327
copy = False
2333
2328
2334
2329
if data .dtype .byteorder == ">" :
@@ -2346,6 +2341,7 @@ def _construct_from_dt64_naive(
2346
2341
if data .ndim > 1 :
2347
2342
data = data .ravel ()
2348
2343
2344
+ data_unit = get_unit_from_dtype (new_dtype )
2349
2345
data = tzconversion .tz_localize_to_utc (
2350
2346
data .view ("i8" ), tz , ambiguous = ambiguous , creso = data_unit
2351
2347
)
@@ -2552,7 +2548,7 @@ def _validate_dt64_dtype(dtype):
2552
2548
2553
2549
if (
2554
2550
isinstance (dtype , np .dtype )
2555
- and (dtype .kind != "M" or not is_supported_unit ( get_unit_from_dtype ( dtype ) ))
2551
+ and (dtype .kind != "M" or not is_supported_dtype ( dtype ))
2556
2552
) or not isinstance (dtype , (np .dtype , DatetimeTZDtype )):
2557
2553
raise ValueError (
2558
2554
f"Unexpected value for 'dtype': '{ dtype } '. "
0 commit comments