Skip to content

Commit f6cad26

Browse files
committed
avoid assigning Py_None
1 parent 9dfd732 commit f6cad26

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

src/_arraykit.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,21 @@ AK_ArrayDeepCopy(PyObject* m, PyArrayObject *array, PyObject *memo)
220220
return NULL;
221221
}
222222

223-
// Given a dtype_specifier, which might be a dtype or None, assign a fresh dtype object (or NULL) to dtype_returned. Returns 0 on success, -1 on failure. This will never set dtype_returned to None. Returns a new reference.
223+
// Given a dtype_specifier, which might be a dtype, NULL, or None, assign a fresh dtype object (or NULL) to dtype_returned. Returns 0 on success, -1 on failure. This will not interpret a None dtype_specified as a float dtype. This will never set dtype_returned to None (only NULL). Returns a new reference.
224224
static inline int
225225
AK_DTypeFromSpecifier(PyObject *dtype_specifier, PyArray_Descr **dtype_returned)
226226
{
227227
PyArray_Descr* dtype;
228-
if (PyObject_TypeCheck(dtype_specifier, &PyArrayDescr_Type)) {
228+
if (dtype_specifier == NULL) {
229+
dtype = NULL; // propagate, cannot call into oncverter
230+
}
231+
else if (PyObject_TypeCheck(dtype_specifier, &PyArrayDescr_Type)) {
229232
dtype = (PyArray_Descr* )dtype_specifier;
230233
}
231-
else { // converter2 set NULL for None
234+
else { // converter2 sets NULL for None
232235
PyArray_DescrConverter2(dtype_specifier, &dtype);
233236
}
234-
// make a copy as we will give ownership to array and might mutate
237+
// if not NULL, make a copy as we will give ownership to array and might mutate
235238
if (dtype) {
236239
dtype = PyArray_DescrNew(dtype);
237240
if (dtype == NULL) return -1;
@@ -1222,10 +1225,7 @@ typedef struct AK_CodePointLine{
12221225
Py_UCS4 *buffer_current_ptr;
12231226
Py_ssize_t offsets_current_index;
12241227

1225-
// char *field;
12261228
AK_TypeParser *type_parser;
1227-
1228-
// TODO: these can be combined in an Enum
12291229
bool type_parser_field_active;
12301230
bool type_parser_line_active;
12311231

@@ -2790,7 +2790,7 @@ AK_IterableStrToArray1D(
27902790
Py_UCS4 decc)
27912791
{
27922792
PyArray_Descr* dtype = NULL;
2793-
// will set NULL for None, and propagate NULLs
2793+
// will set dtype_specifier to NULL for None, and propagate NULLs
27942794
if (AK_DTypeFromSpecifier(dtype_specifier, &dtype)) return NULL;
27952795

27962796
// dtype only NULL from here
@@ -2975,12 +2975,6 @@ iterable_str_to_array_1d(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kwarg
29752975
&decimalchar))
29762976
return NULL;
29772977

2978-
if (dtype_specifier == NULL) {
2979-
// need to pass this on to explicitly signal that we want type evaluation
2980-
// NOTE: should incref
2981-
dtype_specifier = Py_None;
2982-
}
2983-
29842978
Py_UCS4 tsep;
29852979
if (AK_set_char(
29862980
"thousandschar",

0 commit comments

Comments
 (0)