@@ -37,7 +37,6 @@ from pandas._libs.tslibs.np_datetime cimport (
3737    NPY_DATETIMEUNIT,
3838    NPY_FR_ns,
3939    check_dts_bounds,
40-     dtstruct_to_dt64,
4140    get_datetime64_unit,
4241    get_datetime64_value,
4342    get_implementation_bounds,
@@ -171,7 +170,7 @@ cpdef inline (int64_t, int) precision_from_unit(str unit):
171170    return  m, p
172171
173172
174- cdef inline int64_t get_datetime64_nanos(object  val) except ? - 1 :
173+ cdef inline int64_t get_datetime64_nanos(object  val, NPY_DATETIMEUNIT reso ) except ? - 1 :
175174    """ 
176175    Extract the value and unit from a np.datetime64 object, then convert the 
177176    value to nanoseconds if necessary. 
@@ -187,10 +186,10 @@ cdef inline int64_t get_datetime64_nanos(object val) except? -1:
187186
188187    unit =  get_datetime64_unit(val)
189188
190-     if  unit !=  NPY_FR_ns :
189+     if  unit !=  reso :
191190        pandas_datetime_to_datetimestruct(ival, unit, & dts)
192-         check_dts_bounds(& dts)
193-         ival =  dtstruct_to_dt64( & dts)
191+         check_dts_bounds(& dts, reso )
192+         ival =  npy_datetimestruct_to_datetime(reso,  & dts)
194193
195194    return  ival
196195
@@ -238,7 +237,7 @@ cdef _TSObject convert_to_tsobject(object ts, tzinfo tz, str unit,
238237    if  ts is  None  or  ts is  NaT:
239238        obj.value =  NPY_NAT
240239    elif  is_datetime64_object(ts):
241-         obj.value =  get_datetime64_nanos(ts)
240+         obj.value =  get_datetime64_nanos(ts, NPY_FR_ns )
242241        if  obj.value !=  NPY_NAT:
243242            pandas_datetime_to_datetimestruct(obj.value, NPY_FR_ns, & obj.dts)
244243    elif  is_integer_object(ts):
@@ -403,7 +402,7 @@ cdef _TSObject _create_tsobject_tz_using_offset(npy_datetimestruct dts,
403402        datetime dt
404403        Py_ssize_t pos
405404
406-     value =  dtstruct_to_dt64( & dts)
405+     value =  npy_datetimestruct_to_datetime(NPY_FR_ns,  & dts)
407406    obj.dts =  dts
408407    obj.tzinfo =  pytz.FixedOffset(tzoffset)
409408    obj.value =  tz_localize_to_utc_single(value, obj.tzinfo)
@@ -490,12 +489,12 @@ cdef _TSObject _convert_str_to_tsobject(object ts, tzinfo tz, str unit,
490489        )
491490        if  not  string_to_dts_failed:
492491            try :
493-                 check_dts_bounds(& dts)
492+                 check_dts_bounds(& dts, NPY_FR_ns )
494493                if  out_local ==  1 :
495494                    return  _create_tsobject_tz_using_offset(dts,
496495                                                            out_tzoffset, tz)
497496                else :
498-                     ival =  dtstruct_to_dt64( & dts)
497+                     ival =  npy_datetimestruct_to_datetime(NPY_FR_ns,  & dts)
499498                    if  tz is  not  None :
500499                        #  shift for _localize_tso
501500                        ival =  tz_localize_to_utc_single(ival, tz,
0 commit comments