Skip to content

use ccalendar instead of np_datetime #21549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions pandas/_libs/src/datetime/np_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ int is_leapyear(npy_int64 year) {
((year % 100) != 0 || (year % 400) == 0);
}

/*
* Sakamoto's method, from wikipedia
*/
int dayofweek(int y, int m, int d) {
int day;
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
return (day + 6) % 7;
}

/*
* Adjusts a datetimestruct based on a minutes offset. Assumes
* the current values are valid.g
Expand Down
4 changes: 0 additions & 4 deletions pandas/_libs/src/datetime/np_datetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,11 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta val,
PANDAS_DATETIMEUNIT fr,
pandas_timedeltastruct *result);

int dayofweek(int y, int m, int d);

extern const int days_per_month_table[2][12];

// stuff numpy-derived code needs in header
// ----------------------------------------------------------------------------

int is_leapyear(npy_int64 year);

/*
* Calculates the days offset from the 1970 epoch.
*/
Expand Down
4 changes: 0 additions & 4 deletions pandas/_libs/tslibs/np_datetime.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ cdef extern from "../src/datetime/np_datetime.h":
PANDAS_DATETIMEUNIT fr,
pandas_datetimestruct *result) nogil

int days_per_month_table[2][12]
int dayofweek(int y, int m, int d) nogil
int is_leapyear(int64_t year) nogil


cdef int reverse_ops[6]

Expand Down
10 changes: 2 additions & 8 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ cnp.import_array()
from util cimport is_string_object, is_integer_object

from ccalendar import MONTHS, DAYS
from ccalendar cimport get_days_in_month, dayofweek
from conversion cimport tz_convert_single, pydt_to_i8
from frequencies cimport get_freq_code
from nattype cimport NPY_NAT
from np_datetime cimport (pandas_datetimestruct,
dtstruct_to_dt64, dt64_to_dtstruct,
is_leapyear, days_per_month_table, dayofweek)
dtstruct_to_dt64, dt64_to_dtstruct)

# ---------------------------------------------------------------------
# Constants
Expand Down Expand Up @@ -437,12 +437,6 @@ class BaseOffset(_BaseOffset):
# ----------------------------------------------------------------------
# RelativeDelta Arithmetic

@cython.wraparound(False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use days_per_month_array in ccalendar.pyx?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use days_per_month_array in ccalendar.pyx?

We could import it from the C file, but we can't define it directly in cython. Since part of the point of ccalendar was to move to pure-cython, I'm not sure we want to re-introduce the C dependency. Or if we do, we might as well keep the entire implementation in the C file.

Cython 0.28 supposedly allows for "verbatim C" in the form:

cdef extern from *:
     """
     foo;
     bar;
     """

which could be useful for small snipped. But when I've tried this I get compile-time errors.

@cython.boundscheck(False)
cdef inline int get_days_in_month(int year, int month) nogil:
return days_per_month_table[is_leapyear(year)][month - 1]


cdef inline int year_add_months(pandas_datetimestruct dts, int months) nogil:
"""new year number after shifting pandas_datetimestruct number of months"""
return dts.year + (dts.month + months - 1) / 12
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ def pxd(name):
'_libs.tslibs.offsets': {
'pyxfile': '_libs/tslibs/offsets',
'pxdfiles': ['_libs/src/util',
'_libs/tslibs/ccalendar',
'_libs/tslibs/conversion',
'_libs/tslibs/frequencies',
'_libs/tslibs/nattype'],
Expand Down