2727 astype_overflowsafe ,
2828 fields ,
2929 get_resolution ,
30- get_supported_reso ,
30+ get_supported_dtype ,
3131 get_unit_from_dtype ,
3232 ints_to_pydatetime ,
3333 is_date_array_normalized ,
34- is_supported_unit ,
34+ is_supported_dtype ,
3535 is_unitless ,
3636 normalize_i8_timestamps ,
37- npy_unit_to_abbrev ,
3837 timezones ,
3938 to_offset ,
4039 tz_convert_from_utc ,
@@ -712,7 +711,7 @@ def astype(self, dtype, copy: bool = True):
712711 self .tz is None
713712 and lib .is_np_dtype (dtype , "M" )
714713 and not is_unitless (dtype )
715- and is_supported_unit ( get_unit_from_dtype ( dtype ) )
714+ and is_supported_dtype ( dtype )
716715 ):
717716 # unit conversion e.g. datetime64[s]
718717 res_values = astype_overflowsafe (self ._ndarray , dtype , copy = True )
@@ -2307,7 +2306,7 @@ def _sequence_to_dt64(
23072306 assert isinstance (result , np .ndarray ), type (result )
23082307 assert result .dtype .kind == "M"
23092308 assert result .dtype != "M8"
2310- assert is_supported_unit ( get_unit_from_dtype ( result .dtype ) )
2309+ assert is_supported_dtype ( result .dtype )
23112310 return result , tz
23122311
23132312
@@ -2321,14 +2320,10 @@ def _construct_from_dt64_naive(
23212320 # lib.is_np_dtype(data.dtype)
23222321
23232322 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 ):
23262324 # 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 )
23302326 data = astype_overflowsafe (data , dtype = new_dtype , copy = False )
2331- data_unit = get_unit_from_dtype (new_dtype )
23322327 copy = False
23332328
23342329 if data .dtype .byteorder == ">" :
@@ -2346,6 +2341,7 @@ def _construct_from_dt64_naive(
23462341 if data .ndim > 1 :
23472342 data = data .ravel ()
23482343
2344+ data_unit = get_unit_from_dtype (new_dtype )
23492345 data = tzconversion .tz_localize_to_utc (
23502346 data .view ("i8" ), tz , ambiguous = ambiguous , creso = data_unit
23512347 )
@@ -2552,7 +2548,7 @@ def _validate_dt64_dtype(dtype):
25522548
25532549 if (
25542550 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 ))
25562552 ) or not isinstance (dtype , (np .dtype , DatetimeTZDtype )):
25572553 raise ValueError (
25582554 f"Unexpected value for 'dtype': '{ dtype } '. "
0 commit comments