@@ -17,7 +17,9 @@ from pandas._libs.tslibs.ccalendar import (
1717from pandas._libs.tslibs.ccalendar cimport (
1818 DAY_NANOS,
1919 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+ )
2123from pandas._libs.tslibs.np_datetime cimport (
2224 npy_datetimestruct, pandas_timedeltastruct, dt64_to_dtstruct,
2325 td64_to_tdstruct)
@@ -155,19 +157,10 @@ def get_start_end_field(const int64_t[:] dtindex, str field,
155157 int end_month = 12
156158 int start_month = 1
157159 ndarray[int8_t] out
158- ndarray[int32_t, ndim= 2 ] _month_offset
159160 bint isleap
160161 npy_datetimestruct dts
161162 int mo_off, dom, doy, dow, ldom
162163
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-
171164 out = np.zeros(count, dtype = ' int8' )
172165
173166 if freqstr:
@@ -226,10 +219,10 @@ def get_start_end_field(const int64_t[:] dtindex, str field,
226219
227220 dt64_to_dtstruct(dtindex[i], & dts)
228221 isleap = is_leapyear(dts.year)
229- mo_off = _month_offset [isleap, dts.month - 1 ]
222+ mo_off = month_offset [isleap * 13 + dts.month - 1 ]
230223 dom = dts.day
231224 doy = mo_off + dom
232- ldom = _month_offset [isleap, dts.month]
225+ ldom = month_offset [isleap * 13 + dts.month]
233226 dow = dayofweek(dts.year, dts.month, dts.day)
234227
235228 if (ldom == doy and dow < 5 ) or (
@@ -244,10 +237,10 @@ def get_start_end_field(const int64_t[:] dtindex, str field,
244237
245238 dt64_to_dtstruct(dtindex[i], & dts)
246239 isleap = is_leapyear(dts.year)
247- mo_off = _month_offset [isleap, dts.month - 1 ]
240+ mo_off = month_offset [isleap * 13 + dts.month - 1 ]
248241 dom = dts.day
249242 doy = mo_off + dom
250- ldom = _month_offset [isleap, dts.month]
243+ ldom = month_offset [isleap * 13 + dts.month]
251244
252245 if ldom == doy:
253246 out[i] = 1
@@ -288,10 +281,10 @@ def get_start_end_field(const int64_t[:] dtindex, str field,
288281
289282 dt64_to_dtstruct(dtindex[i], & dts)
290283 isleap = is_leapyear(dts.year)
291- mo_off = _month_offset [isleap, dts.month - 1 ]
284+ mo_off = month_offset [isleap * 13 + dts.month - 1 ]
292285 dom = dts.day
293286 doy = mo_off + dom
294- ldom = _month_offset [isleap, dts.month]
287+ ldom = month_offset [isleap * 13 + dts.month]
295288 dow = dayofweek(dts.year, dts.month, dts.day)
296289
297290 if ((dts.month - end_month) % 3 == 0 ) and (
@@ -307,10 +300,10 @@ def get_start_end_field(const int64_t[:] dtindex, str field,
307300
308301 dt64_to_dtstruct(dtindex[i], & dts)
309302 isleap = is_leapyear(dts.year)
310- mo_off = _month_offset [isleap, dts.month - 1 ]
303+ mo_off = month_offset [isleap * 13 + dts.month - 1 ]
311304 dom = dts.day
312305 doy = mo_off + dom
313- ldom = _month_offset [isleap, dts.month]
306+ ldom = month_offset [isleap * 13 + dts.month]
314307
315308 if ((dts.month - end_month) % 3 == 0 ) and (ldom == doy):
316309 out[i] = 1
@@ -352,10 +345,10 @@ def get_start_end_field(const int64_t[:] dtindex, str field,
352345 dt64_to_dtstruct(dtindex[i], & dts)
353346 isleap = is_leapyear(dts.year)
354347 dom = dts.day
355- mo_off = _month_offset [isleap, dts.month - 1 ]
348+ mo_off = month_offset [isleap * 13 + dts.month - 1 ]
356349 doy = mo_off + dom
357350 dow = dayofweek(dts.year, dts.month, dts.day)
358- ldom = _month_offset [isleap, dts.month]
351+ ldom = month_offset [isleap * 13 + dts.month]
359352
360353 if (dts.month == end_month) and (
361354 (ldom == doy and dow < 5 ) or (
@@ -370,10 +363,10 @@ def get_start_end_field(const int64_t[:] dtindex, str field,
370363
371364 dt64_to_dtstruct(dtindex[i], & dts)
372365 isleap = is_leapyear(dts.year)
373- mo_off = _month_offset [isleap, dts.month - 1 ]
366+ mo_off = month_offset [isleap * 13 + dts.month - 1 ]
374367 dom = dts.day
375368 doy = mo_off + dom
376- ldom = _month_offset [isleap, dts.month]
369+ ldom = month_offset [isleap * 13 + dts.month]
377370
378371 if (dts.month == end_month) and (ldom == doy):
379372 out[i] = 1
0 commit comments