@@ -49,30 +49,31 @@ from pandas._libs.tslibs.tzconversion cimport (
49
49
50
50
cdef inline object create_datetime_from_ts(
51
51
int64_t value, npy_datetimestruct dts,
52
- object tz, object freq):
52
+ object tz, object freq, bint fold ):
53
53
""" convenience routine to construct a datetime.datetime from its parts """
54
54
return datetime(dts.year, dts.month, dts.day, dts.hour,
55
- dts.min, dts.sec, dts.us, tz)
55
+ dts.min, dts.sec, dts.us, tz, fold = fold )
56
56
57
57
58
58
cdef inline object create_date_from_ts(
59
59
int64_t value, npy_datetimestruct dts,
60
- object tz, object freq):
60
+ object tz, object freq, bint fold ):
61
61
""" convenience routine to construct a datetime.date from its parts """
62
+ # GH 25057 add fold argument to match other func_create signatures
62
63
return date(dts.year, dts.month, dts.day)
63
64
64
65
65
66
cdef inline object create_time_from_ts(
66
67
int64_t value, npy_datetimestruct dts,
67
- object tz, object freq):
68
+ object tz, object freq, bint fold ):
68
69
""" convenience routine to construct a datetime.time from its parts """
69
- return time(dts.hour, dts.min, dts.sec, dts.us, tz)
70
+ return time(dts.hour, dts.min, dts.sec, dts.us, tz, fold = fold )
70
71
71
72
72
73
@ cython.wraparound (False )
73
74
@ cython.boundscheck (False )
74
75
def ints_to_pydatetime (const int64_t[:] arr , object tz = None , object freq = None ,
75
- str box = " datetime" ):
76
+ bint fold = 0 , str box = " datetime" ):
76
77
"""
77
78
Convert an i8 repr to an ndarray of datetimes, date, time or Timestamp
78
79
@@ -83,6 +84,13 @@ def ints_to_pydatetime(const int64_t[:] arr, object tz=None, object freq=None,
83
84
convert to this timezone
84
85
freq : str/Offset, default None
85
86
freq to convert
87
+ fold : bint, default is 0
88
+ Due to daylight saving time, one wall clock time can occur twice
89
+ when shifting from summer to winter time; fold describes whether the
90
+ datetime-like corresponds to the first (0) or the second time (1)
91
+ the wall clock hits the ambiguous time
92
+
93
+ .. versionadded:: 1.1.0
86
94
box : {'datetime', 'timestamp', 'date', 'time'}, default 'datetime'
87
95
If datetime, convert to datetime.datetime
88
96
If date, convert to datetime.date
@@ -104,7 +112,7 @@ def ints_to_pydatetime(const int64_t[:] arr, object tz=None, object freq=None,
104
112
str typ
105
113
int64_t value, delta, local_value
106
114
ndarray[object ] result = np.empty(n, dtype = object )
107
- object (* func_create)(int64_t, npy_datetimestruct, object , object )
115
+ object (* func_create)(int64_t, npy_datetimestruct, object , object , bint )
108
116
109
117
if box == " date" :
110
118
assert (tz is None ), " tz should be None when converting to date"
@@ -129,7 +137,7 @@ def ints_to_pydatetime(const int64_t[:] arr, object tz=None, object freq=None,
129
137
result[i] = < object > NaT
130
138
else :
131
139
dt64_to_dtstruct(value, & dts)
132
- result[i] = func_create(value, dts, tz, freq)
140
+ result[i] = func_create(value, dts, tz, freq, fold )
133
141
elif is_tzlocal(tz):
134
142
for i in range (n):
135
143
value = arr[i]
@@ -141,7 +149,7 @@ def ints_to_pydatetime(const int64_t[:] arr, object tz=None, object freq=None,
141
149
# using the i8 representation.
142
150
local_value = tz_convert_utc_to_tzlocal(value, tz)
143
151
dt64_to_dtstruct(local_value, & dts)
144
- result[i] = func_create(value, dts, tz, freq)
152
+ result[i] = func_create(value, dts, tz, freq, fold )
145
153
else :
146
154
trans, deltas, typ = get_dst_info(tz)
147
155
@@ -155,7 +163,7 @@ def ints_to_pydatetime(const int64_t[:] arr, object tz=None, object freq=None,
155
163
else :
156
164
# Adjust datetime64 timestamp, recompute datetimestruct
157
165
dt64_to_dtstruct(value + delta, & dts)
158
- result[i] = func_create(value, dts, tz, freq)
166
+ result[i] = func_create(value, dts, tz, freq, fold )
159
167
160
168
elif typ == ' dateutil' :
161
169
# no zone-name change for dateutil tzs - dst etc
@@ -168,7 +176,7 @@ def ints_to_pydatetime(const int64_t[:] arr, object tz=None, object freq=None,
168
176
# Adjust datetime64 timestamp, recompute datetimestruct
169
177
pos = trans.searchsorted(value, side = ' right' ) - 1
170
178
dt64_to_dtstruct(value + deltas[pos], & dts)
171
- result[i] = func_create(value, dts, tz, freq)
179
+ result[i] = func_create(value, dts, tz, freq, fold )
172
180
else :
173
181
# pytz
174
182
for i in range (n):
@@ -182,7 +190,7 @@ def ints_to_pydatetime(const int64_t[:] arr, object tz=None, object freq=None,
182
190
new_tz = tz._tzinfos[tz._transition_info[pos]]
183
191
184
192
dt64_to_dtstruct(value + deltas[pos], & dts)
185
- result[i] = func_create(value, dts, new_tz, freq)
193
+ result[i] = func_create(value, dts, new_tz, freq, fold )
186
194
187
195
return result
188
196
0 commit comments