diff --git a/pandas/src/datetime.pxd b/pandas/src/datetime.pxd index 2147c26768319..1147d31b7fb1d 100644 --- a/pandas/src/datetime.pxd +++ b/pandas/src/datetime.pxd @@ -93,7 +93,7 @@ cdef extern from "datetime/np_datetime.h": void pandas_datetime_to_datetimestruct(npy_datetime val, PANDAS_DATETIMEUNIT fr, pandas_datetimestruct *result) - int _days_per_month_table[2][12] + int days_per_month_table[2][12] int dayofweek(int y, int m, int d) int is_leapyear(int64_t year) diff --git a/pandas/src/datetime.pyx b/pandas/src/datetime.pyx index 6458f2f8e95a9..49ca606467382 100644 --- a/pandas/src/datetime.pyx +++ b/pandas/src/datetime.pyx @@ -1419,7 +1419,7 @@ def monthrange(int64_t year, int64_t month): if month < 1 or month > 12: raise ValueError("bad month number 0; must be 1-12") - days = _days_per_month_table[is_leapyear(year)][month-1] + days = days_per_month_table[is_leapyear(year)][month-1] return (dayofweek(year, month, 1), days) diff --git a/pandas/src/datetime/np_datetime.c b/pandas/src/datetime/np_datetime.c index ad2ffacbb49dc..527ce615917cf 100644 --- a/pandas/src/datetime/np_datetime.c +++ b/pandas/src/datetime/np_datetime.c @@ -36,6 +36,11 @@ #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask #endif +const int days_per_month_table[2][12] = { + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, + { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } +}; + /* * Returns 1 if the given year is a leap year, 0 otherwise. */ @@ -52,7 +57,7 @@ int is_leapyear(npy_int64 year) int dayofweek(int y, int m, int d) { int day; - static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; + static const int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; y -= m < 3; day = (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7; // convert to python day @@ -97,12 +102,12 @@ add_minutes_to_datetimestruct(pandas_datetimestruct *dts, int minutes) dts->month = 12; } isleap = is_leapyear(dts->year); - dts->day += _days_per_month_table[isleap][dts->month-1]; + dts->day += days_per_month_table[isleap][dts->month-1]; } else if (dts->day > 28) { isleap = is_leapyear(dts->year); - if (dts->day > _days_per_month_table[isleap][dts->month-1]) { - dts->day -= _days_per_month_table[isleap][dts->month-1]; + if (dts->day > days_per_month_table[isleap][dts->month-1]) { + dts->day -= days_per_month_table[isleap][dts->month-1]; dts->month++; if (dts->month > 12) { dts->year++; @@ -120,7 +125,7 @@ get_datetimestruct_days(const pandas_datetimestruct *dts) { int i, month; npy_int64 year, days = 0; - int *month_lengths; + const int *month_lengths; year = dts->year - 1970; days = year * 365; @@ -160,7 +165,7 @@ get_datetimestruct_days(const pandas_datetimestruct *dts) days += year / 400; } - month_lengths = _days_per_month_table[is_leapyear(dts->year)]; + month_lengths = days_per_month_table[is_leapyear(dts->year)]; month = dts->month - 1; /* Add the months */ @@ -250,10 +255,11 @@ add_seconds_to_datetimestruct(pandas_datetimestruct *dts, int seconds) static void set_datetimestruct_days(npy_int64 days, pandas_datetimestruct *dts) { - int *month_lengths, i; + const int *month_lengths; + int i; dts->year = days_to_yearsdays(&days); - month_lengths = _days_per_month_table[is_leapyear(dts->year)]; + month_lengths = days_per_month_table[is_leapyear(dts->year)]; for (i = 0; i < 12; ++i) { if (days < month_lengths[i]) { @@ -348,7 +354,7 @@ convert_pydatetime_to_datetimestruct(PyObject *obj, pandas_datetimestruct *out, } isleap = is_leapyear(out->year); if (out->day < 1 || - out->day > _days_per_month_table[isleap][out->month-1]) { + out->day > days_per_month_table[isleap][out->month-1]) { goto invalid_date; } diff --git a/pandas/src/datetime/np_datetime.h b/pandas/src/datetime/np_datetime.h index 281c4a56569fb..f200d3a289c06 100644 --- a/pandas/src/datetime/np_datetime.h +++ b/pandas/src/datetime/np_datetime.h @@ -57,10 +57,7 @@ void pandas_datetime_to_datetimestruct(npy_datetime val, PANDAS_DATETIMEUNIT fr, int dayofweek(int y, int m, int d); -static int _days_per_month_table[2][12] = { - { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, - { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } -}; +extern const int days_per_month_table[2][12]; // stuff numpy-derived code needs in header // ---------------------------------------------------------------------------- diff --git a/pandas/src/datetime/np_datetime_strings.c b/pandas/src/datetime/np_datetime_strings.c index a7b6d3b5fdfbc..77ad8533f2831 100644 --- a/pandas/src/datetime/np_datetime_strings.c +++ b/pandas/src/datetime/np_datetime_strings.c @@ -46,7 +46,7 @@ typedef time_t NPY_TIME_T; /*// linux complains.*/ /*static void _suppress_unused_variable_warning(void)*/ /*{*/ -/* int x = _days_per_month_table[0][0];*/ +/* int x = days_per_month_table[0][0];*/ /* x = x;*/ /* int y = _month_offset[0][0];*/ @@ -229,6 +229,7 @@ convert_datetimestruct_utc_to_local(pandas_datetimestruct *out_dts_local, return 0; } +#if 0 /* * Converts a datetimestruct in local time to a datetimestruct in UTC. * @@ -303,6 +304,7 @@ convert_datetimestruct_local_to_utc(pandas_datetimestruct *out_dts_utc, return 0; } +#endif /* int */ /* parse_python_string(PyObject* obj, pandas_datetimestruct *dts) { */ @@ -593,7 +595,7 @@ parse_iso_8601_datetime(char *str, int len, out->day = 10 * (substr[0] - '0') + (substr[1] - '0'); if (out->day < 1 || - out->day > _days_per_month_table[year_leap][out->month-1]) { + out->day > days_per_month_table[year_leap][out->month-1]) { PyErr_Format(PyExc_ValueError, "Day out of range in datetime string \"%s\"", str); goto error; diff --git a/pandas/src/numpy_helper.h b/pandas/src/numpy_helper.h index a643a90615c57..b61878d3a03bd 100644 --- a/pandas/src/numpy_helper.h +++ b/pandas/src/numpy_helper.h @@ -44,7 +44,7 @@ infer_type(PyObject* obj) { } PANDAS_INLINE npy_int64 -get_nat() { +get_nat(void) { return NPY_MIN_INT64; } diff --git a/pandas/src/offsets.pyx b/pandas/src/offsets.pyx index 6874950181751..5868ca5210e33 100644 --- a/pandas/src/offsets.pyx +++ b/pandas/src/offsets.pyx @@ -218,7 +218,7 @@ cdef class MonthOffset(_Offset): self.m -= 12 self.y += 1 self.ly = is_leapyear(self.y) - days += _days_per_month_table[self.ly][self.m] + days += days_per_month_table[self.ly][self.m] self.m += 1 self.t += days * us_in_day @@ -238,7 +238,7 @@ cdef class MonthOffset(_Offset): self.m += 12 self.y -= 1 self.ly = is_leapyear(self.y) - days += _days_per_month_table[self.ly][self.m] + days += days_per_month_table[self.ly][self.m] self.t -= days * us_in_day @@ -286,7 +286,7 @@ cdef class DayOfMonthOffset(_Offset): cdef: int64_t tmp, days - days = _days_per_month_table[self.ly][self.m] + days = days_per_month_table[self.ly][self.m] self.t += days * us_in_day self.dow = (self.dow + days) % 7 @@ -300,7 +300,7 @@ cdef class DayOfMonthOffset(_Offset): cdef: int64_t tmp, days - days = _days_per_month_table[self.ly][(self.m - 1) % 12] + days = days_per_month_table[self.ly][(self.m - 1) % 12] self.t -= days * us_in_day self.dow = (self.dow - days) % 7 diff --git a/pandas/src/period.c b/pandas/src/period.c index 484ff42d1ea94..4e7ab44c7b150 100644 --- a/pandas/src/period.c +++ b/pandas/src/period.c @@ -1027,10 +1027,10 @@ npy_int64 get_period_ordinal(int year, int month, int day, int hour, int minute, int second, int freq) { - npy_int64 absdays, delta; + npy_int64 absdays, delta; npy_int64 weeks, days; - npy_int64 adj_ordinal, ordinal, day_adj; - int freq_group, fmonth, mdiff, quarter; + npy_int64 ordinal, day_adj; + int freq_group, fmonth, mdiff; freq_group = get_freq_group(freq); if (freq == FR_SEC) {