@@ -17,7 +17,9 @@ from pandas._libs.tslibs.ccalendar import (
17
17
from pandas._libs.tslibs.ccalendar cimport (
18
18
DAY_NANOS,
19
19
get_days_in_month, is_leapyear, dayofweek, get_week_of_year,
20
- get_day_of_year, get_iso_calendar, iso_calendar_t)
20
+ get_day_of_year, get_iso_calendar, iso_calendar_t,
21
+ month_offset,
22
+ )
21
23
from pandas._libs.tslibs.np_datetime cimport (
22
24
npy_datetimestruct, pandas_timedeltastruct, dt64_to_dtstruct,
23
25
td64_to_tdstruct)
@@ -155,19 +157,10 @@ def get_start_end_field(const int64_t[:] dtindex, str field,
155
157
int end_month = 12
156
158
int start_month = 1
157
159
ndarray[int8_t] out
158
- ndarray[int32_t, ndim= 2 ] _month_offset
159
160
bint isleap
160
161
npy_datetimestruct dts
161
162
int mo_off, dom, doy, dow, ldom
162
163
163
- _month_offset = np.array(
164
- [
165
- [0 , 31 , 59 , 90 , 120 , 151 , 181 , 212 , 243 , 273 , 304 , 334 , 365 ],
166
- [0 , 31 , 60 , 91 , 121 , 152 , 182 , 213 , 244 , 274 , 305 , 335 , 366 ],
167
- ],
168
- dtype = np.int32,
169
- )
170
-
171
164
out = np.zeros(count, dtype = ' int8' )
172
165
173
166
if freqstr:
@@ -226,10 +219,10 @@ def get_start_end_field(const int64_t[:] dtindex, str field,
226
219
227
220
dt64_to_dtstruct(dtindex[i], & dts)
228
221
isleap = is_leapyear(dts.year)
229
- mo_off = _month_offset [isleap, dts.month - 1 ]
222
+ mo_off = month_offset [isleap * 13 + dts.month - 1 ]
230
223
dom = dts.day
231
224
doy = mo_off + dom
232
- ldom = _month_offset [isleap, dts.month]
225
+ ldom = month_offset [isleap * 13 + dts.month]
233
226
dow = dayofweek(dts.year, dts.month, dts.day)
234
227
235
228
if (ldom == doy and dow < 5 ) or (
@@ -244,10 +237,10 @@ def get_start_end_field(const int64_t[:] dtindex, str field,
244
237
245
238
dt64_to_dtstruct(dtindex[i], & dts)
246
239
isleap = is_leapyear(dts.year)
247
- mo_off = _month_offset [isleap, dts.month - 1 ]
240
+ mo_off = month_offset [isleap * 13 + dts.month - 1 ]
248
241
dom = dts.day
249
242
doy = mo_off + dom
250
- ldom = _month_offset [isleap, dts.month]
243
+ ldom = month_offset [isleap * 13 + dts.month]
251
244
252
245
if ldom == doy:
253
246
out[i] = 1
@@ -288,10 +281,10 @@ def get_start_end_field(const int64_t[:] dtindex, str field,
288
281
289
282
dt64_to_dtstruct(dtindex[i], & dts)
290
283
isleap = is_leapyear(dts.year)
291
- mo_off = _month_offset [isleap, dts.month - 1 ]
284
+ mo_off = month_offset [isleap * 13 + dts.month - 1 ]
292
285
dom = dts.day
293
286
doy = mo_off + dom
294
- ldom = _month_offset [isleap, dts.month]
287
+ ldom = month_offset [isleap * 13 + dts.month]
295
288
dow = dayofweek(dts.year, dts.month, dts.day)
296
289
297
290
if ((dts.month - end_month) % 3 == 0 ) and (
@@ -307,10 +300,10 @@ def get_start_end_field(const int64_t[:] dtindex, str field,
307
300
308
301
dt64_to_dtstruct(dtindex[i], & dts)
309
302
isleap = is_leapyear(dts.year)
310
- mo_off = _month_offset [isleap, dts.month - 1 ]
303
+ mo_off = month_offset [isleap * 13 + dts.month - 1 ]
311
304
dom = dts.day
312
305
doy = mo_off + dom
313
- ldom = _month_offset [isleap, dts.month]
306
+ ldom = month_offset [isleap * 13 + dts.month]
314
307
315
308
if ((dts.month - end_month) % 3 == 0 ) and (ldom == doy):
316
309
out[i] = 1
@@ -352,10 +345,10 @@ def get_start_end_field(const int64_t[:] dtindex, str field,
352
345
dt64_to_dtstruct(dtindex[i], & dts)
353
346
isleap = is_leapyear(dts.year)
354
347
dom = dts.day
355
- mo_off = _month_offset [isleap, dts.month - 1 ]
348
+ mo_off = month_offset [isleap * 13 + dts.month - 1 ]
356
349
doy = mo_off + dom
357
350
dow = dayofweek(dts.year, dts.month, dts.day)
358
- ldom = _month_offset [isleap, dts.month]
351
+ ldom = month_offset [isleap * 13 + dts.month]
359
352
360
353
if (dts.month == end_month) and (
361
354
(ldom == doy and dow < 5 ) or (
@@ -370,10 +363,10 @@ def get_start_end_field(const int64_t[:] dtindex, str field,
370
363
371
364
dt64_to_dtstruct(dtindex[i], & dts)
372
365
isleap = is_leapyear(dts.year)
373
- mo_off = _month_offset [isleap, dts.month - 1 ]
366
+ mo_off = month_offset [isleap * 13 + dts.month - 1 ]
374
367
dom = dts.day
375
368
doy = mo_off + dom
376
- ldom = _month_offset [isleap, dts.month]
369
+ ldom = month_offset [isleap * 13 + dts.month]
377
370
378
371
if (dts.month == end_month) and (ldom == doy):
379
372
out[i] = 1
0 commit comments