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 all commits
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
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/ccalendar.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from cython cimport Py_ssize_t
from numpy cimport int64_t, int32_t


cdef int dayofweek(int y, int m, int m) nogil
cdef int dayofweek(int y, int m, int d) nogil
cdef bint is_leapyear(int64_t year) nogil
cpdef int32_t get_days_in_month(int year, Py_ssize_t month) nogil
cpdef int32_t get_week_of_year(int year, int month, int day) nogil
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 @@ -450,12 +450,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
3 changes: 1 addition & 2 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ from timezones cimport is_utc, is_tzlocal, get_utcoffset, get_dst_info
from timedeltas cimport delta_to_nanoseconds

cimport ccalendar
from ccalendar cimport dayofweek, get_day_of_year
from ccalendar cimport dayofweek, get_day_of_year, is_leapyear
from ccalendar import MONTH_NUMBERS
from ccalendar cimport is_leapyear
from conversion cimport tz_convert_utc_to_tzlocal
from frequencies cimport (get_freq_code, get_base_alias,
get_to_timestamp_base, get_freq_str,
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