@@ -44,6 +44,7 @@ from pandas._libs.tslibs.ccalendar cimport (
44
44
from pandas._libs.tslibs.nattype cimport NPY_NAT
45
45
from pandas._libs.tslibs.np_datetime cimport (
46
46
NPY_DATETIMEUNIT,
47
+ NPY_FR_ns,
47
48
dt64_to_dtstruct,
48
49
get_unit_from_dtype,
49
50
npy_datetimestruct,
@@ -139,13 +140,18 @@ def month_position_check(fields, weekdays) -> str | None:
139
140
140
141
@ cython.wraparound (False )
141
142
@ cython.boundscheck (False )
142
- def get_date_name_field (const int64_t[:] dtindex , str field , object locale = None ):
143
+ def get_date_name_field (
144
+ const int64_t[:] dtindex ,
145
+ str field ,
146
+ object locale = None ,
147
+ NPY_DATETIMEUNIT reso = NPY_FR_ns,
148
+ ):
143
149
"""
144
150
Given a int64-based datetime index, return array of strings of date
145
151
name based on requested field (e.g. day_name)
146
152
"""
147
153
cdef:
148
- Py_ssize_t i, count = len ( dtindex)
154
+ Py_ssize_t i, count = dtindex.shape[ 0 ]
149
155
ndarray[object ] out, names
150
156
npy_datetimestruct dts
151
157
int dow
@@ -163,7 +169,7 @@ def get_date_name_field(const int64_t[:] dtindex, str field, object locale=None)
163
169
out[i] = np.nan
164
170
continue
165
171
166
- dt64_to_dtstruct (dtindex[i], & dts)
172
+ pandas_datetime_to_datetimestruct (dtindex[i], reso , & dts)
167
173
dow = dayofweek(dts.year, dts.month, dts.day)
168
174
out[i] = names[dow].capitalize()
169
175
@@ -178,7 +184,7 @@ def get_date_name_field(const int64_t[:] dtindex, str field, object locale=None)
178
184
out[i] = np.nan
179
185
continue
180
186
181
- dt64_to_dtstruct (dtindex[i], & dts)
187
+ pandas_datetime_to_datetimestruct (dtindex[i], reso , & dts)
182
188
out[i] = names[dts.month].capitalize()
183
189
184
190
else :
@@ -201,35 +207,39 @@ cdef inline bint _is_on_month(int month, int compare_month, int modby) nogil:
201
207
202
208
@ cython.wraparound (False )
203
209
@ cython.boundscheck (False )
204
- def get_start_end_field (ndarray dt64values , str field ,
205
- str freqstr = None , int month_kw = 12 ):
210
+ def get_start_end_field (
211
+ const int64_t[:] dtindex ,
212
+ str field ,
213
+ str freqstr = None ,
214
+ int month_kw = 12 ,
215
+ NPY_DATETIMEUNIT reso = NPY_FR_ns,
216
+ ):
206
217
"""
207
218
Given an int64-based datetime index return array of indicators
208
219
of whether timestamps are at the start/end of the month/quarter/year
209
220
(defined by frequency).
210
221
211
222
Parameters
212
223
----------
213
- dt64values : ndarray[datetime64], any resolution
224
+ dtindex : ndarray[int64]
214
225
field : str
215
226
frestr : str or None, default None
216
227
month_kw : int, default 12
228
+ reso : NPY_DATETIMEUNIT, default NPY_FR_ns
217
229
218
230
Returns
219
231
-------
220
232
ndarray[bool]
221
233
"""
222
234
cdef:
223
235
Py_ssize_t i
224
- int count = dt64values.size
236
+ int count = dtindex.shape[ 0 ]
225
237
bint is_business = 0
226
238
int end_month = 12
227
239
int start_month = 1
228
240
ndarray[int8_t] out
229
241
npy_datetimestruct dts
230
242
int compare_month, modby
231
- ndarray dtindex = dt64values.view(" i8" )
232
- NPY_DATETIMEUNIT reso = get_unit_from_dtype(dt64values.dtype)
233
243
234
244
out = np.zeros(count, dtype = ' int8' )
235
245
0 commit comments