@@ -72,6 +72,7 @@ from pandas._libs.tslibs.nattype cimport (
72
72
)
73
73
from pandas._libs.tslibs.tzconversion cimport (
74
74
bisect_right_i8,
75
+ infer_datetuil_fold,
75
76
localize_tzinfo_api,
76
77
tz_localize_to_utc_single,
77
78
)
@@ -530,7 +531,7 @@ cdef _TSObject _create_tsobject_tz_using_offset(npy_datetimestruct dts,
530
531
if typ == ' dateutil' :
531
532
tdata = < int64_t* > cnp.PyArray_DATA(trans)
532
533
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)
534
535
535
536
# Keep the converter same as PyDateTime's
536
537
dt = datetime(obj.dts.year, obj.dts.month, obj.dts.day,
@@ -714,7 +715,7 @@ cdef inline void _localize_tso(_TSObject obj, tzinfo tz):
714
715
local_val = obj.value + deltas[pos]
715
716
716
717
# 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)
718
719
else :
719
720
# All other cases have len(deltas) == 1. As of 2018-07-17
720
721
# (and 2022-03-07), all test cases that get here have
@@ -726,49 +727,6 @@ cdef inline void _localize_tso(_TSObject obj, tzinfo tz):
726
727
obj.tzinfo = tz
727
728
728
729
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
-
772
730
cdef inline datetime _localize_pydatetime(datetime dt, tzinfo tz):
773
731
"""
774
732
Take a datetime/Timestamp in UTC and localizes to timezone tz.
@@ -802,24 +760,3 @@ cpdef inline datetime localize_pydatetime(datetime dt, tzinfo tz):
802
760
elif isinstance (dt, ABCTimestamp):
803
761
return dt.tz_localize(tz)
804
762
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