Skip to content

Commit 43f1bc8

Browse files
authored
Refactor Extension Modules (#53346)
* Working refactor with setuptools * Meson updates * fixed missing source files * Missing graft
1 parent 4c3af48 commit 43f1bc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+120
-158
lines changed

.pre-commit-config.yaml

+1-5
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ repos:
6565
rev: 1.6.1
6666
hooks:
6767
- id: cpplint
68-
# We don't lint all C files because we don't want to lint any that are built
69-
# from Cython files nor do we want to lint C files that we didn't modify for
70-
# this particular codebase (e.g. src/headers, src/klib). However,
71-
# we can lint all header files since they aren't "generated" like C files are.
72-
exclude: ^pandas/_libs/src/(klib|headers)/
68+
exclude: ^pandas/_libs/include/pandas/vendored/klib
7369
args: [
7470
--quiet,
7571
'--extensions=c,h',

MANIFEST.in

+1-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,4 @@ prune pandas/tests/io/parser/data
5757

5858
# Selectively re-add *.cxx files that were excluded above
5959
graft pandas/_libs/src
60-
graft pandas/_libs/tslibs/src
61-
include pandas/_libs/pd_parser.h
62-
include pandas/_libs/pd_parser.c
60+
graft pandas/_libs/include

pandas/_libs/tslibs/src/datetime/pd_datetime.h renamed to pandas/_libs/include/pandas/datetime/pd_datetime.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ See NUMPY_LICENSE.txt for the license.
2222
#endif // NPY_NO_DEPRECATED_API
2323

2424
#include <numpy/ndarraytypes.h>
25-
#include "np_datetime.h"
26-
#include "np_datetime_strings.h"
27-
#include "date_conversions.h"
25+
#include "pandas/vendored/numpy/datetime/np_datetime.h"
26+
#include "pandas/vendored/numpy/datetime/np_datetime_strings.h"
27+
#include "pandas/datetime/date_conversions.h"
2828

2929
#ifdef __cplusplus
3030
extern "C" {

pandas/_libs/pd_parser.h renamed to pandas/_libs/include/pandas/parser/pd_parser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern "C" {
1414

1515
#define PY_SSIZE_T_CLEAN
1616
#include <Python.h>
17-
#include "src/parser/tokenizer.h"
17+
#include "pandas/parser/tokenizer.h"
1818

1919
typedef struct {
2020
int (*to_double)(char *, double *, char, char, int *);

pandas/_libs/src/parser/tokenizer.h renamed to pandas/_libs/include/pandas/parser/tokenizer.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ See LICENSE for the license
1919
#define ERROR_INVALID_CHARS 3
2020

2121
#include <stdint.h>
22-
#include "../inline_helper.h"
23-
#include "../headers/portable.h"
22+
#include "pandas/inline_helper.h"
23+
#include "pandas/portable.h"
2424

25-
#include "khash.h"
25+
#include "pandas/vendored/klib/khash.h"
2626

2727
#define STREAM_INIT_SIZE 32
2828

pandas/_libs/src/headers/portable.h renamed to pandas/_libs/include/pandas/portable.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
/*
2+
Copyright (c) 2016, PyData Development Team
3+
All rights reserved.
4+
5+
Distributed under the terms of the BSD Simplified License.
6+
7+
The full license is in the LICENSE file, distributed with this software.
8+
*/
9+
110
#pragma once
211

312
#include <string.h>
413

514
#if defined(_MSC_VER)
6-
#define strcasecmp( s1, s2 ) _stricmp( s1, s2 )
15+
#define strcasecmp(s1, s2) _stricmp(s1, s2)
716
#endif
817

918
// GH-23516 - works around locale perf issues

pandas/_libs/src/skiplist.h renamed to pandas/_libs/include/pandas/skiplist.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Python recipe (https://rhettinger.wordpress.com/2010/02/06/lost-knowledge/)
1919
#include <stdio.h>
2020
#include <stdlib.h>
2121
#include <string.h>
22-
#include "inline_helper.h"
22+
#include "pandas/inline_helper.h"
2323

2424
PANDAS_INLINE float __skiplist_nanf(void) {
2525
const union {

pandas/_libs/src/klib/khash.h renamed to pandas/_libs/include/pandas/vendored/klib/khash.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int main() {
112112
#include <stdlib.h>
113113
#include <string.h>
114114
#include <limits.h>
115-
#include "../inline_helper.h"
115+
#include "pandas/inline_helper.h"
116116

117117

118118
// hooks for memory allocator, C-runtime allocator used per default

pandas/_libs/src/ujson/lib/ultrajson.h renamed to pandas/_libs/include/pandas/vendored/ujson/lib/ultrajson.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ tree doesn't have cyclic references.
5353

5454
#include <stdio.h>
5555
#include <wchar.h>
56-
#include "../../headers/portable.h"
56+
#include "pandas/portable.h"
5757

5858
// Don't output any extra whitespaces when encoding
5959
#define JSON_NO_EXTRA_WHITESPACE

pandas/_libs/khash.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ from numpy cimport (
1515
)
1616

1717

18-
cdef extern from "khash_python.h":
18+
cdef extern from "pandas/vendored/klib/khash_python.h":
1919
const int KHASH_TRACE_DOMAIN
2020

2121
ctypedef uint32_t khuint_t

pandas/_libs/khash_for_primitive_helper.pxi.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ primitive_types = [('int64', 'int64_t'),
2424

2525
{{for name, c_type in primitive_types}}
2626

27-
cdef extern from "khash_python.h":
27+
cdef extern from "pandas/vendored/klib/khash_python.h":
2828
ctypedef struct kh_{{name}}_t:
2929
khuint_t n_buckets, size, n_occupied, upper_bound
3030
uint32_t *flags

pandas/_libs/lib.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ cdef extern from "numpy/arrayobject.h":
9393
cdef extern from "numpy/ndarrayobject.h":
9494
bint PyArray_CheckScalar(obj) nogil
9595

96-
cdef extern from "pd_parser.h":
96+
cdef extern from "pandas/parser/pd_parser.h":
9797
int floatify(object, float64_t *result, int *maybe_int) except -1
9898
void PandasParser_IMPORT()
9999

pandas/_libs/meson.build

+18-30
Original file line numberDiff line numberDiff line change
@@ -61,53 +61,41 @@ subdir('tslibs')
6161
libs_sources = {
6262
# Dict of extension name -> dict of {sources, include_dirs, and deps}
6363
# numpy include dir is implicitly included
64-
'algos': {'sources': ['algos.pyx', _algos_common_helper, _algos_take_helper, _khash_primitive_helper],
65-
'include_dirs': klib_include},
64+
'algos': {'sources': ['algos.pyx', _algos_common_helper, _algos_take_helper, _khash_primitive_helper]},
6665
'arrays': {'sources': ['arrays.pyx']},
6766
'groupby': {'sources': ['groupby.pyx']},
6867
'hashing': {'sources': ['hashing.pyx']},
69-
'hashtable': {'sources': ['hashtable.pyx', _khash_primitive_helper, _hashtable_class_helper, _hashtable_func_helper],
70-
'include_dirs': klib_include},
71-
'index': {'sources': ['index.pyx', _index_class_helper],
72-
'include_dirs': [klib_include, 'tslibs']},
68+
'hashtable': {'sources': ['hashtable.pyx', _khash_primitive_helper, _hashtable_class_helper, _hashtable_func_helper]},
69+
'index': {'sources': ['index.pyx', _index_class_helper]},
7370
'indexing': {'sources': ['indexing.pyx']},
7471
'internals': {'sources': ['internals.pyx']},
75-
'interval': {'sources': ['interval.pyx', _intervaltree_helper],
76-
'include_dirs': [klib_include, 'tslibs']},
72+
'interval': {'sources': ['interval.pyx', _intervaltree_helper]},
7773
'join': {'sources': ['join.pyx', _khash_primitive_helper],
78-
'include_dirs': klib_include,
7974
'deps': _khash_primitive_helper_dep},
80-
'lib': {'sources': ['lib.pyx', 'src/parser/tokenizer.c'],
81-
'include_dirs': [klib_include, inc_datetime]},
82-
'missing': {'sources': ['missing.pyx'],
83-
'include_dirs': [inc_datetime]},
84-
'pandas_datetime': {'sources': ['tslibs/src/datetime/np_datetime.c',
85-
'tslibs/src/datetime/np_datetime_strings.c',
86-
'tslibs/src/datetime/date_conversions.c',
87-
'tslibs/src/datetime/pd_datetime.c']},
88-
#'include_dirs':
75+
'lib': {'sources': ['lib.pyx', 'src/parser/tokenizer.c']},
76+
'missing': {'sources': ['missing.pyx']},
77+
'pandas_datetime': {'sources': ['src/vendored/numpy/datetime/np_datetime.c',
78+
'src/vendored/numpy/datetime/np_datetime_strings.c',
79+
'src/datetime/date_conversions.c',
80+
'src/datetime/pd_datetime.c']},
8981
'pandas_parser': {'sources': ['src/parser/tokenizer.c',
9082
'src/parser/io.c',
91-
'pd_parser.c'],
92-
'include_dirs': [klib_include]},
83+
'src/parser/pd_parser.c']},
9384
'parsers': {'sources': ['parsers.pyx', 'src/parser/tokenizer.c', 'src/parser/io.c'],
94-
'include_dirs': [klib_include, 'src'],
9585
'deps': _khash_primitive_helper_dep},
96-
'json': {'sources': ['src/ujson/python/ujson.c',
97-
'src/ujson/python/objToJSON.c',
98-
'src/ujson/python/JSONtoObj.c',
99-
'src/ujson/lib/ultrajsonenc.c',
100-
'src/ujson/lib/ultrajsondec.c'],
101-
'include_dirs': ['tslibs/src/datetime', 'src/ujson/lib', 'src/ujson/python']},
86+
'json': {'sources': ['src/vendored/ujson/python/ujson.c',
87+
'src/vendored/ujson/python/objToJSON.c',
88+
'src/vendored/ujson/python/JSONtoObj.c',
89+
'src/vendored/ujson/lib/ultrajsonenc.c',
90+
'src/vendored/ujson/lib/ultrajsondec.c']},
10291
'ops': {'sources': ['ops.pyx']},
10392
'ops_dispatch': {'sources': ['ops_dispatch.pyx']},
10493
'properties': {'sources': ['properties.pyx']},
10594
'reshape': {'sources': ['reshape.pyx']},
10695
'sas': {'sources': ['sas.pyx']},
10796
'byteswap': {'sources': ['byteswap.pyx']},
10897
'sparse': {'sources': ['sparse.pyx', _sparse_op_helper]},
109-
'tslib': {'sources': ['tslib.pyx'],
110-
'include_dirs': inc_datetime},
98+
'tslib': {'sources': ['tslib.pyx']},
11199
'testing': {'sources': ['testing.pyx']},
112100
'writers': {'sources': ['writers.pyx']}
113101
}
@@ -118,7 +106,7 @@ foreach ext_name, ext_dict : libs_sources
118106
ext_name,
119107
ext_dict.get('sources'),
120108
cython_args: ['--include-dir', meson.current_build_dir()],
121-
include_directories: [inc_np] + ext_dict.get('include_dirs', ''),
109+
include_directories: [inc_np, inc_pd],
122110
dependencies: ext_dict.get('deps', ''),
123111
subdir: 'pandas/_libs',
124112
install: true

pandas/_libs/parsers.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ cdef:
117117
int64_t DEFAULT_CHUNKSIZE = 256 * 1024
118118

119119

120-
cdef extern from "headers/portable.h":
120+
cdef extern from "pandas/portable.h":
121121
# I *think* this is here so that strcasecmp is defined on Windows
122122
# so we don't get
123123
# `parsers.obj : error LNK2001: unresolved external symbol strcasecmp`
@@ -127,7 +127,7 @@ cdef extern from "headers/portable.h":
127127
pass
128128

129129

130-
cdef extern from "parser/tokenizer.h":
130+
cdef extern from "pandas/parser/tokenizer.h":
131131

132132
ctypedef enum ParserState:
133133
START_RECORD
@@ -245,7 +245,7 @@ cdef extern from "parser/tokenizer.h":
245245

246246
void COLITER_NEXT(coliter_t, const char *) nogil
247247

248-
cdef extern from "pd_parser.h":
248+
cdef extern from "pandas/parser/pd_parser.h":
249249
void *new_rd_source(object obj) except NULL
250250

251251
int del_rd_source(void *src)

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ The full license is in the LICENSE file, distributed with this software.
88
// Conversion routines that are useful for serialization,
99
// but which don't interact with JSON objects directly
1010

11-
#include "date_conversions.h"
12-
#include "np_datetime.h"
13-
#include "np_datetime_strings.h"
11+
#include "pandas/datetime/date_conversions.h"
12+
#include "pandas/vendored/numpy/datetime/np_datetime.h"
13+
#include "pandas/vendored/numpy/datetime/np_datetime_strings.h"
1414

1515
/*
1616
* Function: scaleNanosecToUnit

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
2020
#include <Python.h>
2121

2222
#include "datetime.h"
23-
#include "pd_datetime.h"
23+
#include "pandas/datetime/pd_datetime.h"
2424

2525

2626
static void pandas_datetime_destructor(PyObject *op) {

pandas/_libs/src/parser/io.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Distributed under the terms of the BSD Simplified License.
77
The full license is in the LICENSE file, distributed with this software.
88
*/
99

10-
#include "io.h"
10+
#include "pandas/parser/io.h"
1111

1212
/*
1313
On-disk FILE, uncompressed

pandas/_libs/pd_parser.c renamed to pandas/_libs/src/parser/pd_parser.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Distributed under the terms of the BSD Simplified License.
88
*/
99
#define _PANDAS_PARSER_IMPL
1010

11-
#include "pd_parser.h"
12-
#include "src/parser/io.h"
11+
#include "pandas/parser/pd_parser.h"
12+
#include "pandas/parser/io.h"
1313

1414
static int to_double(char *item, double *p_value, char sci, char decimal,
1515
int *maybe_int) {

pandas/_libs/src/parser/tokenizer.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ GitHub. See Python Software Foundation License and BSD licenses for these.
1717
1818
*/
1919

20-
#include "tokenizer.h"
20+
#include "pandas/parser/tokenizer.h"
2121

2222
#include <ctype.h>
2323
#include <float.h>
2424
#include <math.h>
2525

26-
#include "../headers/portable.h"
26+
#include "pandas/portable.h"
2727

2828
void coliter_setup(coliter_t *self, parser_t *parser, int64_t i,
2929
int64_t start) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
2525
#include <numpy/arrayobject.h>
2626
#include <numpy/arrayscalars.h>
2727
#include <numpy/ndarraytypes.h>
28-
#include "np_datetime.h"
28+
#include "pandas/vendored/numpy/datetime/np_datetime.h"
2929

3030

3131
const int days_per_month_table[2][12] = {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ This file implements string parsing and creation for NumPy datetime.
3434
#include <numpy/arrayscalars.h>
3535
#include <numpy/ndarraytypes.h>
3636

37-
#include "np_datetime.h"
38-
#include "np_datetime_strings.h"
37+
#include "pandas/vendored/numpy/datetime/np_datetime.h"
38+
#include "pandas/vendored/numpy/datetime/np_datetime_strings.h"
3939

4040

4141
/*

pandas/_libs/src/ujson/lib/ultrajsondec.c renamed to pandas/_libs/src/vendored/ujson/lib/ultrajsondec.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Numeric decoder derived from TCL library
4646
#include <stdlib.h>
4747
#include <string.h>
4848
#include <wchar.h>
49-
#include "ultrajson.h"
49+
#include "pandas/vendored/ujson/lib/ultrajson.h"
5050

5151
#ifndef TRUE
5252
#define TRUE 1

pandas/_libs/src/ujson/lib/ultrajsonenc.c renamed to pandas/_libs/src/vendored/ujson/lib/ultrajsonenc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Numeric decoder derived from TCL library
4545
#include <stdio.h>
4646
#include <stdlib.h>
4747
#include <string.h>
48-
#include "ultrajson.h"
48+
#include "pandas/vendored/ujson/lib/ultrajson.h"
4949

5050
#ifndef TRUE
5151
#define TRUE 1

pandas/_libs/src/ujson/python/JSONtoObj.c renamed to pandas/_libs/src/vendored/ujson/python/JSONtoObj.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Numeric decoder derived from TCL library
4040
#define PY_SSIZE_T_CLEAN
4141
#include <Python.h>
4242
#include <numpy/arrayobject.h>
43-
#include <ultrajson.h>
43+
#include "pandas/vendored/ujson/lib/ultrajson.h"
4444

4545
#define PRINTMARK()
4646

pandas/_libs/src/ujson/python/objToJSON.c renamed to pandas/_libs/src/vendored/ujson/python/objToJSON.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ Numeric decoder derived from TCL library
4646
#include <numpy/arrayscalars.h>
4747
#include <numpy/ndarraytypes.h>
4848
#include <numpy/npy_math.h>
49-
#include <ultrajson.h>
49+
#include "pandas/vendored/ujson/lib/ultrajson.h"
5050
#include "datetime.h"
51-
#include "pd_datetime.h"
51+
#include "pandas/datetime/pd_datetime.h"
5252

5353
npy_int64 get_nat(void) { return NPY_MIN_INT64; }
5454

pandas/_libs/src/ujson/python/ujson.c renamed to pandas/_libs/src/vendored/ujson/python/ujson.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Numeric decoder derived from TCL library
3535
* Copyright (c) 1994 Sun Microsystems, Inc.
3636
*/
3737

38-
#include "version.h"
38+
#include "pandas/vendored/ujson/python/version.h"
3939
#define PY_SSIZE_T_CLEAN
4040
#include <Python.h>
4141
#define PY_ARRAY_UNIQUE_SYMBOL UJSON_NUMPY

0 commit comments

Comments
 (0)