Skip to content

Use cythonize for build #19484

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

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cdef extern from "Python.h":
import numpy as np
from numpy cimport int64_t

cdef extern from "compat_helper.h":
cdef extern from "src/compat_helper.h":
cdef int slice_get_indices(PyObject* s, Py_ssize_t length,
Py_ssize_t *start, Py_ssize_t *stop,
Py_ssize_t *step,
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/khash.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from cpython cimport PyObject
from numpy cimport int64_t, uint64_t, int32_t, uint32_t, float64_t

cdef extern from "khash_python.h":
cdef extern from "src/klib/khash_python.h":
ctypedef uint32_t khint_t
ctypedef khint_t khiter_t

Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -914,4 +914,4 @@ def indices_fast(object index, ndarray[int64_t] labels, list keys,
return result


include "inference.pyx"
include "src/inference.pyx"
6 changes: 3 additions & 3 deletions pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ cdef double NEGINF = -INF
cdef extern from "errno.h":
int errno

cdef extern from "headers/portable.h":
cdef extern from "src/headers/portable.h":
# I *think* this is here so that strcasecmp is defined on Windows
# so we don't get
# `parsers.obj : error LNK2001: unresolved external symbol strcasecmp`
Expand All @@ -87,7 +87,7 @@ except NameError:
basestring = str


cdef extern from "parser/tokenizer.h":
cdef extern from "src/parser/tokenizer.h":

ctypedef enum ParserState:
START_RECORD
Expand Down Expand Up @@ -243,7 +243,7 @@ cdef extern from "parser/tokenizer.h":
int to_boolean(const char *item, uint8_t *val) nogil


cdef extern from "parser/io.h":
cdef extern from "src/parser/io.h":
void *new_mmap(char *fname)
int del_mmap(void *src)
void* buffer_mmap_bytes(void *source, size_t nbytes,
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/src/parser/tokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ See LICENSE for the license

#include "../headers/stdint.h"

#include "khash.h"
#include "../klib/khash.h"

#define CHUNKSIZE 1024 * 256
#define KB 1024
Expand Down
185 changes: 0 additions & 185 deletions pandas/_libs/src/util.pxd

This file was deleted.

7 changes: 3 additions & 4 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ from tslibs.np_datetime cimport (check_dts_bounds,
_string_to_dts,
dt64_to_dtstruct, dtstruct_to_dt64,
pydatetime_to_dt64, pydate_to_dt64,
get_datetime64_value,
days_per_month_table,
dayofweek, is_leapyear)
get_datetime64_value)
from tslibs.np_datetime import OutOfBoundsDatetime

from tslibs.parsing import parse_datetime_string
Expand All @@ -40,6 +38,7 @@ import pytz
UTC = pytz.utc


from tslibs.ccalendar cimport get_days_in_month, dayofweek
from tslibs.timedeltas cimport cast_from_unit
from tslibs.timedeltas import Timedelta
from tslibs.timezones cimport (is_utc, is_tzlocal, is_fixed_offset,
Expand Down Expand Up @@ -749,7 +748,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 = get_days_in_month(year, month)

return (dayofweek(year, month, 1), days)

Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/tslibs/np_datetime.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +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

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 @@ -390,12 +390,6 @@ class BaseOffset(_BaseOffset):
# ----------------------------------------------------------------------
# RelativeDelta Arithmetic

@cython.wraparound(False)
@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
15 changes: 11 additions & 4 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ from cpython.datetime cimport PyDateTime_Check, PyDateTime_IMPORT
PyDateTime_IMPORT

from np_datetime cimport (pandas_datetimestruct, dtstruct_to_dt64,
dt64_to_dtstruct, is_leapyear)
dt64_to_dtstruct)

cimport util
from util cimport is_period_object, is_string_object, INT32_MIN
from util cimport is_period_object, is_string_object

from pandas._libs.missing cimport is_null_datetimelike

Expand All @@ -34,6 +34,7 @@ from timezones cimport is_utc, is_tzlocal, get_utcoffset, get_dst_info
from timedeltas cimport delta_to_nanoseconds

from ccalendar import MONTH_NUMBERS
from ccalendar cimport is_leapyear
from frequencies cimport (get_freq_code, get_base_alias,
get_to_timestamp_base, get_freq_str,
get_rule_month)
Expand All @@ -46,7 +47,13 @@ from pandas.tseries import offsets
from pandas.tseries import frequencies


cdef extern from "period_helper.h":
cdef extern from "../src/numpy_helper.h":
object char_to_string(char*)

cdef extern from "../src/headers/stdint.h":
enum: INT32_MIN

cdef extern from "../src/period_helper.h":
ctypedef struct date_info:
int64_t absdate
double abstime
Expand Down Expand Up @@ -339,7 +346,7 @@ cdef object _period_strftime(int64_t value, int freq, object fmt):

formatted = c_strftime(&dinfo, <char*> fmt)

result = util.char_to_string(formatted)
result = char_to_string(formatted)
free(formatted)

for i in range(len(extra_fmts)):
Expand Down
Loading