Skip to content

Commit 221c0c1

Browse files
committed
increased usage of PyArray_Empty when possible
1 parent cf49b8b commit 221c0c1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/_arraykit.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,11 +1577,13 @@ AK_CPL_to_array_float(AK_CodePointLine* cpl, PyArray_Descr* dtype, char tsep, ch
15771577
Py_ssize_t count = cpl->offsets_count;
15781578
npy_intp dims[] = {count};
15791579

1580-
PyObject *array = PyArray_Zeros(1, dims, dtype, 0); // steals dtype ref
1580+
// NOTE: empty prefered over zeros
1581+
PyObject *array = PyArray_Empty(1, dims, dtype, 0);
15811582
if (array == NULL) {
15821583
// expected array to steal dtype reference
15831584
return NULL;
15841585
}
1586+
15851587
// initialize error code to 0; only update on error.
15861588
int error = 0;
15871589
bool matched_elsize = true;
@@ -1654,7 +1656,8 @@ AK_CPL_to_array_int(AK_CodePointLine* cpl, PyArray_Descr* dtype, char tsep)
16541656
Py_ssize_t count = cpl->offsets_count;
16551657
npy_intp dims[] = {count};
16561658

1657-
PyObject *array = PyArray_Zeros(1, dims, dtype, 0); // steals dtype ref
1659+
// NOTE: empty prefered over zeros
1660+
PyObject *array = PyArray_Empty(1, dims, dtype, 0);
16581661
if (array == NULL) {
16591662
// expected array to steal dtype reference
16601663
return NULL;
@@ -1726,7 +1729,8 @@ AK_CPL_to_array_uint(AK_CodePointLine* cpl, PyArray_Descr* dtype, char tsep)
17261729
Py_ssize_t count = cpl->offsets_count;
17271730
npy_intp dims[] = {count};
17281731

1729-
PyObject *array = PyArray_Zeros(1, dims, dtype, 0); // steals dtype ref
1732+
// NOTE: empty prefered over zeros
1733+
PyObject *array = PyArray_Empty(1, dims, dtype, 0);
17301734
if (array == NULL) {
17311735
// expected array to steal dtype reference
17321736
return NULL;
@@ -1812,7 +1816,8 @@ AK_CPL_to_array_unicode(AK_CodePointLine* cpl, PyArray_Descr* dtype)
18121816
capped_points = true;
18131817
}
18141818

1815-
// assuming this is contiguous
1819+
// NOTE: it is assumed (though not verified in some testing) that we need to get zereod array here as we might copy to the array less than the full item size width
1820+
18161821
PyObject *array = PyArray_Zeros(1, dims, dtype, 0); // steals dtype ref
18171822
if (array == NULL) {
18181823
// expected array to steal dtype reference
@@ -1877,7 +1882,7 @@ AK_CPL_to_array_bytes(AK_CodePointLine* cpl, PyArray_Descr* dtype)
18771882
capped_points = true;
18781883
}
18791884

1880-
PyObject *array = PyArray_Zeros(1, dims, dtype, 0); // steals dtype ref
1885+
PyObject *array = PyArray_Zeros(1, dims, dtype, 0);
18811886
if (array == NULL) {
18821887
// expected array to steal dtype reference
18831888
return NULL;

0 commit comments

Comments
 (0)