Skip to content

Commit 6e73e58

Browse files
committed
new handling for npy complex types
1 parent 2eae222 commit 6e73e58

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/delimited_to_arrays.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ AK_CPL_Free(AK_CodePointLine* cpl)
10701070
PyMem_Free(cpl->offsets);
10711071
if (cpl->type_parser) {
10721072
PyMem_Free(cpl->type_parser);
1073+
// TODO: use AK_TP_Free
10731074
}
10741075
PyMem_Free(cpl);
10751076
}

src/methods.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,18 +558,19 @@ isna_element(PyObject *m, PyObject *args, PyObject *kwargs)
558558
Py_complex val = ((PyComplexObject*)element)->cval;
559559
return PyBool_FromLong(isnan(val.real) || isnan(val.imag));
560560
}
561+
// TODO: fix!
561562
if (PyArray_IsScalar(element, Complex64)) {
562563
npy_cfloat val = PyArrayScalar_VAL(element, Complex64);
563-
return PyBool_FromLong(isnan(val.real) || isnan(val.imag));
564+
return PyBool_FromLong(isnan(npy_creal(val)) || isnan(npy_cimag(val)));
564565
}
565566
if (PyArray_IsScalar(element, Complex128)) {
566567
npy_cdouble val = PyArrayScalar_VAL(element, Complex128);
567-
return PyBool_FromLong(isnan(val.real) || isnan(val.imag));
568+
return PyBool_FromLong(isnan(npy_creal(val)) || isnan(npy_cimag(val)));
568569
}
569570
# ifdef PyComplex256ArrType_Type
570571
if (PyArray_IsScalar(element, Complex256)) {
571572
npy_clongdouble val = PyArrayScalar_VAL(element, Complex256);
572-
return PyBool_FromLong(isnan(val.real) || isnan(val.imag));
573+
return PyBool_FromLong(isnan(npy_creal(val)) || isnan(npy_cimag(val)));
573574
}
574575
# endif
575576

src/tri_map.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
static inline NPY_DATETIMEUNIT
1515
AK_dt_unit_from_array(PyArrayObject* a) {
1616
// This is based on get_datetime_metadata_from_dtype in the NumPy source, but that function is private. This does not check that the dtype is of the appropriate type.
17-
PyArray_DatetimeMetaData* dma = &(((PyArray_DatetimeDTypeMetaData *)PyArray_DESCR(a)->c_metadata)->meta);
17+
PyArray_Descr* dt = PyArray_DESCR(a); // borrowed ref
18+
PyArray_DatetimeMetaData* dma = &(((PyArray_DatetimeDTypeMetaData *)PyDataType_C_METADATA(dt))->meta);
19+
// PyArray_DatetimeMetaData* dma = &(((PyArray_DatetimeDTypeMetaData *)PyArray_DESCR(a)->c_metadata)->meta);
1820
return dma->base;
1921
}
2022

@@ -856,9 +858,9 @@ AK_TM_fill_object(TriMapObject* tm,
856858
#define AK_TM_TRANSFER_FLEXIBLE(c_type) do { \
857859
Py_ssize_t one_count = from_src ? tm->src_one_count : tm->dst_one_count;\
858860
TriMapOne* one_pairs = from_src ? tm->src_one : tm->dst_one; \
859-
npy_intp t_element_size = PyArray_DESCR(array_to)->elsize; \
861+
npy_intp t_element_size = PyArray_ITEMSIZE(array_to); \
860862
npy_intp t_element_cp = t_element_size / sizeof(c_type); \
861-
npy_intp f_element_size = PyArray_DESCR(array_from)->elsize; \
863+
npy_intp f_element_size = PyArray_ITEMSIZE(array_from); \
862864
c_type* array_to_data = (c_type*)PyArray_DATA(array_to); \
863865
c_type* f; \
864866
c_type* t; \
@@ -906,7 +908,7 @@ AK_TM_fill_unicode(TriMapObject* tm,
906908

907909
Py_UCS4* array_to_data = (Py_UCS4*)PyArray_DATA(array_to);
908910
// code points per element
909-
npy_intp cp = PyArray_DESCR(array_to)->elsize / UCS4_SIZE;
911+
npy_intp cp = PyArray_ITEMSIZE(array_to) / UCS4_SIZE;
910912

911913
bool decref_fill_value = false;
912914
if (PyBytes_Check(fill_value)) {
@@ -948,7 +950,7 @@ AK_TM_fill_string(TriMapObject* tm,
948950
? tm->final_src_fill : tm->final_dst_fill);
949951

950952
char* array_to_data = (char*)PyArray_DATA(array_to);
951-
npy_intp cp = PyArray_DESCR(array_to)->elsize;
953+
npy_intp cp = PyArray_ITEMSIZE(array_to);
952954
if (!PyBytes_Check(fill_value)) {
953955
return -1;
954956
}

0 commit comments

Comments
 (0)