-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path_arraykit.c
More file actions
160 lines (146 loc) · 5.19 KB
/
_arraykit.c
File metadata and controls
160 lines (146 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# include "Python.h"
# define PY_ARRAY_UNIQUE_SYMBOL AK_ARRAY_API
# define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
# include "numpy/arrayobject.h"
# include "array_go.h"
# include "array_to_tuple.h"
# include "block_index.h"
# include "delimited_to_arrays.h"
# include "methods.h"
# include "tri_map.h"
# include "auto_map.h"
static PyMethodDef arraykit_methods[] = {
{"immutable_filter", immutable_filter, METH_O, NULL},
{"mloc", mloc, METH_O, NULL},
{"name_filter", name_filter, METH_O, NULL},
{"shape_filter", shape_filter, METH_O, NULL},
{"column_2d_filter", column_2d_filter, METH_O, NULL},
{"column_1d_filter", column_1d_filter, METH_O, NULL},
{"row_1d_filter", row_1d_filter, METH_O, NULL},
{"slice_to_ascending_slice", slice_to_ascending_slice, METH_VARARGS, NULL},
{"array_deepcopy",
(PyCFunction)array_deepcopy,
METH_VARARGS | METH_KEYWORDS,
NULL},
{"array_to_tuple_array", array_to_tuple_array, METH_O, NULL},
{"array_to_tuple_iter", array_to_tuple_iter, METH_O, NULL},
{"resolve_dtype", resolve_dtype, METH_VARARGS, NULL},
{"resolve_dtype_iter", resolve_dtype_iter, METH_O, NULL},
{"first_true_1d",
(PyCFunction)first_true_1d,
METH_VARARGS | METH_KEYWORDS,
NULL},
{"first_true_2d",
(PyCFunction)first_true_2d,
METH_VARARGS | METH_KEYWORDS,
NULL},
{"delimited_to_arrays",
(PyCFunction)delimited_to_arrays,
METH_VARARGS | METH_KEYWORDS,
NULL},
{"iterable_str_to_array_1d",
(PyCFunction)iterable_str_to_array_1d,
METH_VARARGS | METH_KEYWORDS,
NULL},
{"split_after_count",
(PyCFunction)split_after_count,
METH_VARARGS | METH_KEYWORDS,
NULL},
{"count_iteration", count_iteration, METH_O, NULL},
{"nonzero_1d", nonzero_1d, METH_O, NULL},
{"is_objectable_dt64", is_objectable_dt64, METH_O, NULL},
{"is_objectable", is_objectable, METH_O, NULL},
{"astype_array", astype_array, METH_VARARGS, NULL},
{"isna_element",
(PyCFunction)isna_element,
METH_VARARGS | METH_KEYWORDS,
NULL},
{"dtype_from_element", dtype_from_element, METH_O, NULL},
{"get_new_indexers_and_screen",
(PyCFunction)get_new_indexers_and_screen,
METH_VARARGS | METH_KEYWORDS,
NULL},
{NULL},
};
static struct PyModuleDef arraykit_module = {
PyModuleDef_HEAD_INIT,
.m_name = "_arraykit",
.m_doc = NULL,
.m_size = -1,
.m_methods = arraykit_methods,
};
PyObject*
PyInit__arraykit(void)
{
import_array();
ErrorInitTypeBlocks = PyErr_NewExceptionWithDoc(
"arraykit.ErrorInitTypeBlocks",
"RuntimeError error in block initialization.",
PyExc_RuntimeError,
NULL);
if (ErrorInitTypeBlocks == NULL) {
return NULL;
}
NonUniqueError = PyErr_NewExceptionWithDoc(
"arraykit.NonUniqueError",
"ValueError for non-unique values.",
PyExc_ValueError,
NULL);
if (NonUniqueError == NULL) {
return NULL;
}
// store a reference to the deepcopy function
PyObject *copy = PyImport_ImportModule("copy");
if (copy == NULL) {
return NULL;
}
PyObject *deepcopy = PyObject_GetAttrString(copy, "deepcopy");
Py_DECREF(copy);
if (deepcopy == NULL) {
return NULL;
}
// store a year dtype object
PyObject* dt_year_str = PyUnicode_FromString("datetime64[Y]");
if (!dt_year_str) return NULL;
PyArray_Descr* dt_year = NULL;
if (!PyArray_DescrConverter2(dt_year_str, &dt_year)) {
Py_DECREF(dt_year_str);
return NULL;
}
Py_DECREF(dt_year_str);
PyObject *m = PyModule_Create(&arraykit_module);
if (!m ||
PyModule_AddStringConstant(m, "__version__", Py_STRINGIFY(AK_VERSION)) ||
PyType_Ready(&BlockIndexType) ||
PyType_Ready(&BIIterType) ||
PyType_Ready(&BIIterSeqType) ||
PyType_Ready(&BIIterSliceType) ||
PyType_Ready(&BIIterBoolType) ||
PyType_Ready(&BIIterContiguousType) ||
PyType_Ready(&BIIterBlockType) ||
PyType_Ready(&TriMapType) ||
PyType_Ready(&ArrayGOType) ||
PyType_Ready(&AMType) ||
PyType_Ready(&FAMIType) ||
PyType_Ready(&FAMVType) ||
PyType_Ready(&FAMType) ||
PyModule_AddObject(m, "BlockIndex", (PyObject *) &BlockIndexType) ||
PyModule_AddObject(m, "TriMap", (PyObject *) &TriMapType) ||
PyModule_AddObject(m, "ArrayGO", (PyObject *) &ArrayGOType) ||
PyModule_AddObject(m, "deepcopy", deepcopy) ||
PyModule_AddObject(m, "ErrorInitTypeBlocks", ErrorInitTypeBlocks) ||
PyModule_AddObject(m, "AutoMap", (PyObject *)&AMType) ||
PyModule_AddObject(m, "FrozenAutoMap", (PyObject *)&FAMType) ||
PyModule_AddObject(m, "NonUniqueError", NonUniqueError) ||
PyModule_AddObject(m, "dt_year", (PyObject *)dt_year)
){
Py_XDECREF(deepcopy);
Py_XDECREF(dt_year);
Py_XDECREF(m);
return NULL;
}
#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
#endif
return m;
}