From c72e8768c8238900c4c718f8f53f920f77dd88c5 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 2 Aug 2018 03:18:15 -0700 Subject: [PATCH] implement tslibs/src to make tslibs self-contained (#22152) --- pandas/_libs/src/ujson/python/objToJSON.c | 4 +- .../{ => tslibs}/src/datetime/np_datetime.c | 4 ++ .../{ => tslibs}/src/datetime/np_datetime.h | 4 ++ .../src/datetime/np_datetime_strings.c | 4 ++ .../src/datetime/np_datetime_strings.h | 4 ++ pandas/_libs/{ => tslibs}/src/period_helper.c | 24 ++++---- pandas/_libs/{ => tslibs}/src/period_helper.h | 8 ++- setup.py | 55 ++++++++++++++----- 8 files changed, 76 insertions(+), 31 deletions(-) rename pandas/_libs/{ => tslibs}/src/datetime/np_datetime.c (99%) rename pandas/_libs/{ => tslibs}/src/datetime/np_datetime.h (96%) rename pandas/_libs/{ => tslibs}/src/datetime/np_datetime_strings.c (99%) rename pandas/_libs/{ => tslibs}/src/datetime/np_datetime_strings.h (96%) rename pandas/_libs/{ => tslibs}/src/period_helper.c (96%) rename pandas/_libs/{ => tslibs}/src/period_helper.h (97%) diff --git a/pandas/_libs/src/ujson/python/objToJSON.c b/pandas/_libs/src/ujson/python/objToJSON.c index 8c7b92ddeaa81..a5e93640742aa 100644 --- a/pandas/_libs/src/ujson/python/objToJSON.c +++ b/pandas/_libs/src/ujson/python/objToJSON.c @@ -47,8 +47,8 @@ Numeric decoder derived from from TCL library #include // NOLINT(build/include_order) #include // NOLINT(build/include_order) #include // NOLINT(build/include_order) -#include // NOLINT(build/include_order) -#include // 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; diff --git a/pandas/_libs/src/datetime/np_datetime.c b/pandas/_libs/tslibs/src/datetime/np_datetime.c similarity index 99% rename from pandas/_libs/src/datetime/np_datetime.c rename to pandas/_libs/tslibs/src/datetime/np_datetime.c index 663ec66a35db2..1b33f38441253 100644 --- a/pandas/_libs/src/datetime/np_datetime.c +++ b/pandas/_libs/tslibs/src/datetime/np_datetime.c @@ -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 #include diff --git a/pandas/_libs/src/datetime/np_datetime.h b/pandas/_libs/tslibs/src/datetime/np_datetime.h similarity index 96% rename from pandas/_libs/src/datetime/np_datetime.h rename to pandas/_libs/tslibs/src/datetime/np_datetime.h index 04009c6581ac0..9fa85b18dd219 100644 --- a/pandas/_libs/src/datetime/np_datetime.h +++ b/pandas/_libs/tslibs/src/datetime/np_datetime.h @@ -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 #include diff --git a/pandas/_libs/src/datetime/np_datetime_strings.c b/pandas/_libs/tslibs/src/datetime/np_datetime_strings.c similarity index 99% rename from pandas/_libs/src/datetime/np_datetime_strings.c rename to pandas/_libs/tslibs/src/datetime/np_datetime_strings.c index fa96cce1756c8..19ade6fa5add9 100644 --- a/pandas/_libs/src/datetime/np_datetime_strings.c +++ b/pandas/_libs/tslibs/src/datetime/np_datetime_strings.c @@ -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 #include diff --git a/pandas/_libs/src/datetime/np_datetime_strings.h b/pandas/_libs/tslibs/src/datetime/np_datetime_strings.h similarity index 96% rename from pandas/_libs/src/datetime/np_datetime_strings.h rename to pandas/_libs/tslibs/src/datetime/np_datetime_strings.h index 821bb79b345bd..e9a7fd74b05e5 100644 --- a/pandas/_libs/src/datetime/np_datetime_strings.h +++ b/pandas/_libs/tslibs/src/datetime/np_datetime_strings.h @@ -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: * diff --git a/pandas/_libs/src/period_helper.c b/pandas/_libs/tslibs/src/period_helper.c similarity index 96% rename from pandas/_libs/src/period_helper.c rename to pandas/_libs/tslibs/src/period_helper.c index 7dab77131c1a0..4bf3774e35a68 100644 --- a/pandas/_libs/src/period_helper.c +++ b/pandas/_libs/tslibs/src/period_helper.c @@ -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 @@ -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) { @@ -97,8 +101,7 @@ 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 { @@ -106,15 +109,14 @@ PANDAS_INLINE npy_int64 upsample_daytime(npy_int64 ordinal, } } -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); diff --git a/pandas/_libs/src/period_helper.h b/pandas/_libs/tslibs/src/period_helper.h similarity index 97% rename from pandas/_libs/src/period_helper.h rename to pandas/_libs/tslibs/src/period_helper.h index 8f538b261db9e..f0198935bd421 100644 --- a/pandas/_libs/src/period_helper.h +++ b/pandas/_libs/tslibs/src/period_helper.h @@ -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 -#include "headers/stdint.h" -#include "helper.h" #include "limits.h" #include "numpy/ndarraytypes.h" @@ -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; diff --git a/setup.py b/setup.py index f058c8a6e3c99..3289f1e99b87f 100755 --- a/setup.py +++ b/setup.py @@ -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'), @@ -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 @@ -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': { @@ -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', @@ -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': {