@@ -72,6 +72,7 @@ from pandas._libs.tslibs.nattype cimport (
7272)
7373from pandas._libs.tslibs.tzconversion cimport (
7474 bisect_right_i8,
75+ infer_datetuil_fold,
7576 localize_tzinfo_api,
7677 tz_localize_to_utc_single,
7778)
@@ -530,7 +531,7 @@ cdef _TSObject _create_tsobject_tz_using_offset(npy_datetimestruct dts,
530531 if typ == ' dateutil' :
531532 tdata = < int64_t* > cnp.PyArray_DATA(trans)
532533 pos = bisect_right_i8(tdata, obj.value, trans.shape[0 ]) - 1
533- obj.fold = _infer_tsobject_fold (obj, trans, deltas, pos)
534+ obj.fold = infer_datetuil_fold (obj.value , trans, deltas, pos)
534535
535536 # Keep the converter same as PyDateTime's
536537 dt = datetime(obj.dts.year, obj.dts.month, obj.dts.day,
@@ -714,7 +715,7 @@ cdef inline void _localize_tso(_TSObject obj, tzinfo tz):
714715 local_val = obj.value + deltas[pos]
715716
716717 # dateutil supports fold, so we infer fold from value
717- obj.fold = _infer_tsobject_fold (obj, trans, deltas, pos)
718+ obj.fold = infer_datetuil_fold (obj.value , trans, deltas, pos)
718719 else :
719720 # All other cases have len(deltas) == 1. As of 2018-07-17
720721 # (and 2022-03-07), all test cases that get here have
@@ -726,49 +727,6 @@ cdef inline void _localize_tso(_TSObject obj, tzinfo tz):
726727 obj.tzinfo = tz
727728
728729
729- cdef inline bint _infer_tsobject_fold(
730- _TSObject obj,
731- const int64_t[:] trans,
732- const int64_t[:] deltas,
733- intp_t pos,
734- ):
735- """
736- Infer _TSObject fold property from value by assuming 0 and then setting
737- to 1 if necessary.
738-
739- Parameters
740- ----------
741- obj : _TSObject
742- trans : ndarray[int64_t]
743- ndarray of offset transition points in nanoseconds since epoch.
744- deltas : int64_t[:]
745- array of offsets corresponding to transition points in trans.
746- pos : intp_t
747- Position of the last transition point before taking fold into account.
748-
749- Returns
750- -------
751- bint
752- Due to daylight saving time, one wall clock time can occur twice
753- when shifting from summer to winter time; fold describes whether the
754- datetime-like corresponds to the first (0) or the second time (1)
755- the wall clock hits the ambiguous time
756-
757- References
758- ----------
759- .. [1] "PEP 495 - Local Time Disambiguation"
760- https://www.python.org/dev/peps/pep-0495/#the-fold-attribute
761- """
762- cdef:
763- bint fold = 0
764-
765- if pos > 0 :
766- fold_delta = deltas[pos - 1 ] - deltas[pos]
767- if obj.value - fold_delta < trans[pos]:
768- fold = 1
769-
770- return fold
771-
772730cdef inline datetime _localize_pydatetime(datetime dt, tzinfo tz):
773731 """
774732 Take a datetime/Timestamp in UTC and localizes to timezone tz.
@@ -802,24 +760,3 @@ cpdef inline datetime localize_pydatetime(datetime dt, tzinfo tz):
802760 elif isinstance (dt, ABCTimestamp):
803761 return dt.tz_localize(tz)
804762 return _localize_pydatetime(dt, tz)
805-
806-
807- # ----------------------------------------------------------------------
808- # Normalization
809-
810- @ cython.cdivision (False )
811- cdef inline int64_t normalize_i8_stamp(int64_t local_val) nogil:
812- """
813- Round the localized nanosecond timestamp down to the previous midnight.
814-
815- Parameters
816- ----------
817- local_val : int64_t
818-
819- Returns
820- -------
821- int64_t
822- """
823- cdef:
824- int64_t day_nanos = 24 * 3600 * 1 _000_000_000
825- return local_val - (local_val % day_nanos)
0 commit comments