Skip to content

Commit 4cf95ba

Browse files
jbrockmendeljreback
authored andcommitted
implement tslibs/src to make tslibs self-contained (#22152)
1 parent 647f3f0 commit 4cf95ba

File tree

8 files changed

+76
-31
lines changed

8 files changed

+76
-31
lines changed

pandas/_libs/src/ujson/python/objToJSON.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ Numeric decoder derived from from TCL library
4747
#include <numpy/npy_math.h> // NOLINT(build/include_order)
4848
#include <stdio.h> // NOLINT(build/include_order)
4949
#include <ultrajson.h> // NOLINT(build/include_order)
50-
#include <np_datetime.h> // NOLINT(build/include_order)
51-
#include <np_datetime_strings.h> // NOLINT(build/include_order)
50+
#include <../../../tslibs/src/datetime/np_datetime.h> // NOLINT(build/include_order)
51+
#include <../../../tslibs/src/datetime/np_datetime_strings.h> // NOLINT(build/include_order)
5252
#include "datetime.h"
5353

5454
static PyObject *type_decimal;

pandas/_libs/src/datetime/np_datetime.c renamed to pandas/_libs/tslibs/src/datetime/np_datetime.c

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
1616

1717
#define NO_IMPORT
1818

19+
#ifndef NPY_NO_DEPRECATED_API
20+
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
21+
#endif
22+
1923
#include <Python.h>
2024
#include <datetime.h>
2125

pandas/_libs/src/datetime/np_datetime.h renamed to pandas/_libs/tslibs/src/datetime/np_datetime.h

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
1717
#ifndef PANDAS__LIBS_SRC_DATETIME_NP_DATETIME_H_
1818
#define PANDAS__LIBS_SRC_DATETIME_NP_DATETIME_H_
1919

20+
#ifndef NPY_NO_DEPRECATED_API
21+
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
22+
#endif
23+
2024
#include <numpy/ndarraytypes.h>
2125
#include <datetime.h>
2226

pandas/_libs/src/datetime/np_datetime_strings.c renamed to pandas/_libs/tslibs/src/datetime/np_datetime_strings.c

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ This file implements string parsing and creation for NumPy datetime.
2222
#define PY_SSIZE_T_CLEAN
2323
#define NO_IMPORT
2424

25+
#ifndef NPY_NO_DEPRECATED_API
26+
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
27+
#endif
28+
2529
#include <Python.h>
2630

2731
#include <time.h>

pandas/_libs/src/datetime/np_datetime_strings.h renamed to pandas/_libs/tslibs/src/datetime/np_datetime_strings.h

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ This file implements string parsing and creation for NumPy datetime.
2222
#ifndef PANDAS__LIBS_SRC_DATETIME_NP_DATETIME_STRINGS_H_
2323
#define PANDAS__LIBS_SRC_DATETIME_NP_DATETIME_STRINGS_H_
2424

25+
#ifndef NPY_NO_DEPRECATED_API
26+
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
27+
#endif
28+
2529
/*
2630
* Parses (almost) standard ISO 8601 date strings. The differences are:
2731
*

pandas/_libs/src/period_helper.c renamed to pandas/_libs/tslibs/src/period_helper.c

+13-11
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ frequency conversion routines.
1313
See end of file for stuff pandas uses (search for 'pandas').
1414
*/
1515

16+
#ifndef NPY_NO_DEPRECATED_API
17+
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
18+
#endif
19+
1620
#include "period_helper.h"
17-
#include "../datetime/np_datetime.h"
21+
#include "datetime/np_datetime.h"
1822

1923
/* ------------------------------------------------------------------
2024
* Code derived from scikits.timeseries
@@ -79,9 +83,9 @@ static npy_int64 daytime_conversion_factor_matrix[7][7] = {
7983

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

82-
PANDAS_INLINE int min_value(int a, int b) { return a < b ? a : b; }
86+
static int min_value(int a, int b) { return a < b ? a : b; }
8387

84-
PANDAS_INLINE int get_freq_group(int freq) { return (freq / 1000) * 1000; }
88+
static int get_freq_group(int freq) { return (freq / 1000) * 1000; }
8589

8690

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

100-
PANDAS_INLINE npy_int64 upsample_daytime(npy_int64 ordinal,
101-
asfreq_info *af_info) {
104+
static npy_int64 upsample_daytime(npy_int64 ordinal, asfreq_info *af_info) {
102105
if (af_info->is_end) {
103106
return (ordinal + 1) * af_info->intraday_conversion_factor - 1;
104107
} else {
105108
return ordinal * af_info->intraday_conversion_factor;
106109
}
107110
}
108111

109-
PANDAS_INLINE npy_int64 downsample_daytime(npy_int64 ordinal,
110-
asfreq_info *af_info) {
112+
static npy_int64 downsample_daytime(npy_int64 ordinal, asfreq_info *af_info) {
111113
return ordinal / (af_info->intraday_conversion_factor);
112114
}
113115

114-
PANDAS_INLINE npy_int64 transform_via_day(npy_int64 ordinal,
115-
asfreq_info *af_info,
116-
freq_conv_func first_func,
117-
freq_conv_func second_func) {
116+
static npy_int64 transform_via_day(npy_int64 ordinal,
117+
asfreq_info *af_info,
118+
freq_conv_func first_func,
119+
freq_conv_func second_func) {
118120
npy_int64 result;
119121

120122
result = (*first_func)(ordinal, af_info);

pandas/_libs/src/period_helper.h renamed to pandas/_libs/tslibs/src/period_helper.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ frequency conversion routines.
1414
#ifndef PANDAS__LIBS_SRC_PERIOD_HELPER_H_
1515
#define PANDAS__LIBS_SRC_PERIOD_HELPER_H_
1616

17+
#ifndef NPY_NO_DEPRECATED_API
18+
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
19+
#endif
20+
1721
#include <Python.h>
18-
#include "headers/stdint.h"
19-
#include "helper.h"
2022
#include "limits.h"
2123
#include "numpy/ndarraytypes.h"
2224

@@ -74,7 +76,7 @@ frequency conversion routines.
7476

7577
#define FR_UND -10000 /* Undefined */
7678

77-
#define INT_ERR_CODE INT32_MIN
79+
#define INT_ERR_CODE NPY_MIN_INT32
7880

7981
typedef struct asfreq_info {
8082
int is_end;

setup.py

+40-15
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,15 @@ def initialize_options(self):
226226
self._clean_trees = []
227227

228228
base = pjoin('pandas', '_libs', 'src')
229-
dt = pjoin(base, 'datetime')
230-
src = base
229+
tsbase = pjoin('pandas', '_libs', 'tslibs', 'src')
230+
dt = pjoin(tsbase, 'datetime')
231231
util = pjoin('pandas', 'util')
232232
parser = pjoin(base, 'parser')
233233
ujson_python = pjoin(base, 'ujson', 'python')
234234
ujson_lib = pjoin(base, 'ujson', 'lib')
235235
self._clean_exclude = [pjoin(dt, 'np_datetime.c'),
236236
pjoin(dt, 'np_datetime_strings.c'),
237-
pjoin(src, 'period_helper.c'),
237+
pjoin(tsbase, 'period_helper.c'),
238238
pjoin(parser, 'tokenizer.c'),
239239
pjoin(parser, 'io.c'),
240240
pjoin(ujson_python, 'ujson.c'),
@@ -498,16 +498,19 @@ def srcpath(name=None, suffix='.pyx', subdir='src'):
498498
lib_depends = []
499499

500500
common_include = ['pandas/_libs/src/klib', 'pandas/_libs/src']
501+
ts_include = ['pandas/_libs/tslibs/src']
501502

502503

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

507-
np_datetime_headers = ['pandas/_libs/src/datetime/np_datetime.h',
508-
'pandas/_libs/src/datetime/np_datetime_strings.h']
509-
np_datetime_sources = ['pandas/_libs/src/datetime/np_datetime.c',
510-
'pandas/_libs/src/datetime/np_datetime_strings.c']
508+
np_datetime_headers = [
509+
'pandas/_libs/tslibs/src/datetime/np_datetime.h',
510+
'pandas/_libs/tslibs/src/datetime/np_datetime_strings.h']
511+
np_datetime_sources = [
512+
'pandas/_libs/tslibs/src/datetime/np_datetime.c',
513+
'pandas/_libs/tslibs/src/datetime/np_datetime_strings.c']
511514

512515
tseries_depends = np_datetime_headers
513516

@@ -520,13 +523,16 @@ def srcpath(name=None, suffix='.pyx', subdir='src'):
520523
'pyxfile': '_libs/groupby',
521524
'depends': _pxi_dep['groupby']},
522525
'_libs.hashing': {
523-
'pyxfile': '_libs/hashing'},
526+
'pyxfile': '_libs/hashing',
527+
'include': [],
528+
'depends': []},
524529
'_libs.hashtable': {
525530
'pyxfile': '_libs/hashtable',
526531
'depends': (['pandas/_libs/src/klib/khash_python.h'] +
527532
_pxi_dep['hashtable'])},
528533
'_libs.index': {
529534
'pyxfile': '_libs/index',
535+
'include': common_include + ts_include,
530536
'depends': _pxi_dep['index'],
531537
'sources': np_datetime_sources},
532538
'_libs.indexing': {
@@ -541,9 +547,11 @@ def srcpath(name=None, suffix='.pyx', subdir='src'):
541547
'depends': _pxi_dep['join']},
542548
'_libs.lib': {
543549
'pyxfile': '_libs/lib',
550+
'include': common_include + ts_include,
544551
'depends': lib_depends + tseries_depends},
545552
'_libs.missing': {
546553
'pyxfile': '_libs/missing',
554+
'include': common_include + ts_include,
547555
'depends': tseries_depends},
548556
'_libs.parsers': {
549557
'pyxfile': '_libs/parsers',
@@ -570,54 +578,71 @@ def srcpath(name=None, suffix='.pyx', subdir='src'):
570578
'depends': _pxi_dep['sparse']},
571579
'_libs.tslib': {
572580
'pyxfile': '_libs/tslib',
581+
'include': ts_include,
573582
'depends': tseries_depends,
574583
'sources': np_datetime_sources},
575584
'_libs.tslibs.ccalendar': {
576-
'pyxfile': '_libs/tslibs/ccalendar'},
585+
'pyxfile': '_libs/tslibs/ccalendar',
586+
'include': []},
577587
'_libs.tslibs.conversion': {
578588
'pyxfile': '_libs/tslibs/conversion',
589+
'include': ts_include,
579590
'depends': tseries_depends,
580591
'sources': np_datetime_sources},
581592
'_libs.tslibs.fields': {
582593
'pyxfile': '_libs/tslibs/fields',
594+
'include': ts_include,
583595
'depends': tseries_depends,
584596
'sources': np_datetime_sources},
585597
'_libs.tslibs.frequencies': {
586-
'pyxfile': '_libs/tslibs/frequencies'},
598+
'pyxfile': '_libs/tslibs/frequencies',
599+
'include': []},
587600
'_libs.tslibs.nattype': {
588-
'pyxfile': '_libs/tslibs/nattype'},
601+
'pyxfile': '_libs/tslibs/nattype',
602+
'include': []},
589603
'_libs.tslibs.np_datetime': {
590604
'pyxfile': '_libs/tslibs/np_datetime',
605+
'include': ts_include,
591606
'depends': np_datetime_headers,
592607
'sources': np_datetime_sources},
593608
'_libs.tslibs.offsets': {
594609
'pyxfile': '_libs/tslibs/offsets',
610+
'include': ts_include,
595611
'depends': tseries_depends,
596612
'sources': np_datetime_sources},
597613
'_libs.tslibs.parsing': {
598-
'pyxfile': '_libs/tslibs/parsing'},
614+
'pyxfile': '_libs/tslibs/parsing',
615+
'include': []},
599616
'_libs.tslibs.period': {
600617
'pyxfile': '_libs/tslibs/period',
601-
'depends': tseries_depends + ['pandas/_libs/src/period_helper.h'],
602-
'sources': np_datetime_sources + ['pandas/_libs/src/period_helper.c']},
618+
'include': ts_include,
619+
'depends': tseries_depends + [
620+
'pandas/_libs/tslibs/src/period_helper.h'],
621+
'sources': np_datetime_sources + [
622+
'pandas/_libs/tslibs/src/period_helper.c']},
603623
'_libs.tslibs.resolution': {
604624
'pyxfile': '_libs/tslibs/resolution',
625+
'include': ts_include,
605626
'depends': tseries_depends,
606627
'sources': np_datetime_sources},
607628
'_libs.tslibs.strptime': {
608629
'pyxfile': '_libs/tslibs/strptime',
630+
'include': ts_include,
609631
'depends': tseries_depends,
610632
'sources': np_datetime_sources},
611633
'_libs.tslibs.timedeltas': {
612634
'pyxfile': '_libs/tslibs/timedeltas',
635+
'include': ts_include,
613636
'depends': np_datetime_headers,
614637
'sources': np_datetime_sources},
615638
'_libs.tslibs.timestamps': {
616639
'pyxfile': '_libs/tslibs/timestamps',
640+
'include': ts_include,
617641
'depends': tseries_depends,
618642
'sources': np_datetime_sources},
619643
'_libs.tslibs.timezones': {
620-
'pyxfile': '_libs/tslibs/timezones'},
644+
'pyxfile': '_libs/tslibs/timezones',
645+
'include': []},
621646
'_libs.testing': {
622647
'pyxfile': '_libs/testing'},
623648
'_libs.window': {

0 commit comments

Comments
 (0)