Skip to content

Commit

Permalink
implement tslibs/src to make tslibs self-contained (#22152)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and jreback committed Aug 2, 2018
1 parent 647f3f0 commit 4cf95ba
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 31 deletions.
4 changes: 2 additions & 2 deletions pandas/_libs/src/ujson/python/objToJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ Numeric decoder derived from from TCL library
#include <numpy/npy_math.h> // NOLINT(build/include_order)
#include <stdio.h> // NOLINT(build/include_order)
#include <ultrajson.h> // NOLINT(build/include_order)
#include <np_datetime.h> // NOLINT(build/include_order)
#include <np_datetime_strings.h> // NOLINT(build/include_order)
#include <../../../tslibs/src/datetime/np_datetime.h> // NOLINT(build/include_order)
#include <../../../tslibs/src/datetime/np_datetime_strings.h> // NOLINT(build/include_order)
#include "datetime.h"

static PyObject *type_decimal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt

#define NO_IMPORT

#ifndef NPY_NO_DEPRECATED_API
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#endif

#include <Python.h>
#include <datetime.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
#ifndef PANDAS__LIBS_SRC_DATETIME_NP_DATETIME_H_
#define PANDAS__LIBS_SRC_DATETIME_NP_DATETIME_H_

#ifndef NPY_NO_DEPRECATED_API
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#endif

#include <numpy/ndarraytypes.h>
#include <datetime.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ This file implements string parsing and creation for NumPy datetime.
#define PY_SSIZE_T_CLEAN
#define NO_IMPORT

#ifndef NPY_NO_DEPRECATED_API
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#endif

#include <Python.h>

#include <time.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ This file implements string parsing and creation for NumPy datetime.
#ifndef PANDAS__LIBS_SRC_DATETIME_NP_DATETIME_STRINGS_H_
#define PANDAS__LIBS_SRC_DATETIME_NP_DATETIME_STRINGS_H_

#ifndef NPY_NO_DEPRECATED_API
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#endif

/*
* Parses (almost) standard ISO 8601 date strings. The differences are:
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ frequency conversion routines.
See end of file for stuff pandas uses (search for 'pandas').
*/

#ifndef NPY_NO_DEPRECATED_API
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#endif

#include "period_helper.h"
#include "../datetime/np_datetime.h"
#include "datetime/np_datetime.h"

/* ------------------------------------------------------------------
* Code derived from scikits.timeseries
Expand Down Expand Up @@ -79,9 +83,9 @@ static npy_int64 daytime_conversion_factor_matrix[7][7] = {

int max_value(int a, int b) { return a > b ? a : b; }

PANDAS_INLINE int min_value(int a, int b) { return a < b ? a : b; }
static int min_value(int a, int b) { return a < b ? a : b; }

PANDAS_INLINE int get_freq_group(int freq) { return (freq / 1000) * 1000; }
static int get_freq_group(int freq) { return (freq / 1000) * 1000; }


npy_int64 get_daytime_conversion_factor(int from_index, int to_index) {
Expand All @@ -97,24 +101,22 @@ npy_int64 get_daytime_conversion_factor(int from_index, int to_index) {
return daytime_conversion_factor_matrix[row - 6][col - 6];
}

PANDAS_INLINE npy_int64 upsample_daytime(npy_int64 ordinal,
asfreq_info *af_info) {
static npy_int64 upsample_daytime(npy_int64 ordinal, asfreq_info *af_info) {
if (af_info->is_end) {
return (ordinal + 1) * af_info->intraday_conversion_factor - 1;
} else {
return ordinal * af_info->intraday_conversion_factor;
}
}

PANDAS_INLINE npy_int64 downsample_daytime(npy_int64 ordinal,
asfreq_info *af_info) {
static npy_int64 downsample_daytime(npy_int64 ordinal, asfreq_info *af_info) {
return ordinal / (af_info->intraday_conversion_factor);
}

PANDAS_INLINE npy_int64 transform_via_day(npy_int64 ordinal,
asfreq_info *af_info,
freq_conv_func first_func,
freq_conv_func second_func) {
static npy_int64 transform_via_day(npy_int64 ordinal,
asfreq_info *af_info,
freq_conv_func first_func,
freq_conv_func second_func) {
npy_int64 result;

result = (*first_func)(ordinal, af_info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ frequency conversion routines.
#ifndef PANDAS__LIBS_SRC_PERIOD_HELPER_H_
#define PANDAS__LIBS_SRC_PERIOD_HELPER_H_

#ifndef NPY_NO_DEPRECATED_API
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#endif

#include <Python.h>
#include "headers/stdint.h"
#include "helper.h"
#include "limits.h"
#include "numpy/ndarraytypes.h"

Expand Down Expand Up @@ -74,7 +76,7 @@ frequency conversion routines.

#define FR_UND -10000 /* Undefined */

#define INT_ERR_CODE INT32_MIN
#define INT_ERR_CODE NPY_MIN_INT32

typedef struct asfreq_info {
int is_end;
Expand Down
55 changes: 40 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ def initialize_options(self):
self._clean_trees = []

base = pjoin('pandas', '_libs', 'src')
dt = pjoin(base, 'datetime')
src = base
tsbase = pjoin('pandas', '_libs', 'tslibs', 'src')
dt = pjoin(tsbase, 'datetime')
util = pjoin('pandas', 'util')
parser = pjoin(base, 'parser')
ujson_python = pjoin(base, 'ujson', 'python')
ujson_lib = pjoin(base, 'ujson', 'lib')
self._clean_exclude = [pjoin(dt, 'np_datetime.c'),
pjoin(dt, 'np_datetime_strings.c'),
pjoin(src, 'period_helper.c'),
pjoin(tsbase, 'period_helper.c'),
pjoin(parser, 'tokenizer.c'),
pjoin(parser, 'io.c'),
pjoin(ujson_python, 'ujson.c'),
Expand Down Expand Up @@ -498,16 +498,19 @@ def srcpath(name=None, suffix='.pyx', subdir='src'):
lib_depends = []

common_include = ['pandas/_libs/src/klib', 'pandas/_libs/src']
ts_include = ['pandas/_libs/tslibs/src']


lib_depends = lib_depends + ['pandas/_libs/src/numpy_helper.h',
'pandas/_libs/src/parse_helper.h',
'pandas/_libs/src/compat_helper.h']

np_datetime_headers = ['pandas/_libs/src/datetime/np_datetime.h',
'pandas/_libs/src/datetime/np_datetime_strings.h']
np_datetime_sources = ['pandas/_libs/src/datetime/np_datetime.c',
'pandas/_libs/src/datetime/np_datetime_strings.c']
np_datetime_headers = [
'pandas/_libs/tslibs/src/datetime/np_datetime.h',
'pandas/_libs/tslibs/src/datetime/np_datetime_strings.h']
np_datetime_sources = [
'pandas/_libs/tslibs/src/datetime/np_datetime.c',
'pandas/_libs/tslibs/src/datetime/np_datetime_strings.c']

tseries_depends = np_datetime_headers

Expand All @@ -520,13 +523,16 @@ def srcpath(name=None, suffix='.pyx', subdir='src'):
'pyxfile': '_libs/groupby',
'depends': _pxi_dep['groupby']},
'_libs.hashing': {
'pyxfile': '_libs/hashing'},
'pyxfile': '_libs/hashing',
'include': [],
'depends': []},
'_libs.hashtable': {
'pyxfile': '_libs/hashtable',
'depends': (['pandas/_libs/src/klib/khash_python.h'] +
_pxi_dep['hashtable'])},
'_libs.index': {
'pyxfile': '_libs/index',
'include': common_include + ts_include,
'depends': _pxi_dep['index'],
'sources': np_datetime_sources},
'_libs.indexing': {
Expand All @@ -541,9 +547,11 @@ def srcpath(name=None, suffix='.pyx', subdir='src'):
'depends': _pxi_dep['join']},
'_libs.lib': {
'pyxfile': '_libs/lib',
'include': common_include + ts_include,
'depends': lib_depends + tseries_depends},
'_libs.missing': {
'pyxfile': '_libs/missing',
'include': common_include + ts_include,
'depends': tseries_depends},
'_libs.parsers': {
'pyxfile': '_libs/parsers',
Expand All @@ -570,54 +578,71 @@ def srcpath(name=None, suffix='.pyx', subdir='src'):
'depends': _pxi_dep['sparse']},
'_libs.tslib': {
'pyxfile': '_libs/tslib',
'include': ts_include,
'depends': tseries_depends,
'sources': np_datetime_sources},
'_libs.tslibs.ccalendar': {
'pyxfile': '_libs/tslibs/ccalendar'},
'pyxfile': '_libs/tslibs/ccalendar',
'include': []},
'_libs.tslibs.conversion': {
'pyxfile': '_libs/tslibs/conversion',
'include': ts_include,
'depends': tseries_depends,
'sources': np_datetime_sources},
'_libs.tslibs.fields': {
'pyxfile': '_libs/tslibs/fields',
'include': ts_include,
'depends': tseries_depends,
'sources': np_datetime_sources},
'_libs.tslibs.frequencies': {
'pyxfile': '_libs/tslibs/frequencies'},
'pyxfile': '_libs/tslibs/frequencies',
'include': []},
'_libs.tslibs.nattype': {
'pyxfile': '_libs/tslibs/nattype'},
'pyxfile': '_libs/tslibs/nattype',
'include': []},
'_libs.tslibs.np_datetime': {
'pyxfile': '_libs/tslibs/np_datetime',
'include': ts_include,
'depends': np_datetime_headers,
'sources': np_datetime_sources},
'_libs.tslibs.offsets': {
'pyxfile': '_libs/tslibs/offsets',
'include': ts_include,
'depends': tseries_depends,
'sources': np_datetime_sources},
'_libs.tslibs.parsing': {
'pyxfile': '_libs/tslibs/parsing'},
'pyxfile': '_libs/tslibs/parsing',
'include': []},
'_libs.tslibs.period': {
'pyxfile': '_libs/tslibs/period',
'depends': tseries_depends + ['pandas/_libs/src/period_helper.h'],
'sources': np_datetime_sources + ['pandas/_libs/src/period_helper.c']},
'include': ts_include,
'depends': tseries_depends + [
'pandas/_libs/tslibs/src/period_helper.h'],
'sources': np_datetime_sources + [
'pandas/_libs/tslibs/src/period_helper.c']},
'_libs.tslibs.resolution': {
'pyxfile': '_libs/tslibs/resolution',
'include': ts_include,
'depends': tseries_depends,
'sources': np_datetime_sources},
'_libs.tslibs.strptime': {
'pyxfile': '_libs/tslibs/strptime',
'include': ts_include,
'depends': tseries_depends,
'sources': np_datetime_sources},
'_libs.tslibs.timedeltas': {
'pyxfile': '_libs/tslibs/timedeltas',
'include': ts_include,
'depends': np_datetime_headers,
'sources': np_datetime_sources},
'_libs.tslibs.timestamps': {
'pyxfile': '_libs/tslibs/timestamps',
'include': ts_include,
'depends': tseries_depends,
'sources': np_datetime_sources},
'_libs.tslibs.timezones': {
'pyxfile': '_libs/tslibs/timezones'},
'pyxfile': '_libs/tslibs/timezones',
'include': []},
'_libs.testing': {
'pyxfile': '_libs/testing'},
'_libs.window': {
Expand Down

0 comments on commit 4cf95ba

Please sign in to comment.