Skip to content

Commit 15ccbb9

Browse files
committed
Add comment explaining why getitem returns a str
1 parent 1fad632 commit 15ccbb9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

stringdtype/stringdtype/src/dtype.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ stringdtype_getitem(StringDTypeObject *NPY_UNUSED(descr), char **dataptr)
163163
return NULL;
164164
}
165165

166+
/*
167+
* In principle we should return a StringScalar instance here, but
168+
* creating a StringScalar via PyObject_CallFunctionObjArgs has
169+
* approximately 4 times as much overhead than just returning a str
170+
* here. This is due to Python overhead as well as copying the string
171+
* buffer from val_obj to the StringScalar we'd like to return. In
172+
* principle we could avoid this by making a C function like
173+
* PyUnicode_FromStringAndSize that fills a StringScalar instead of a
174+
* str. For now (4-11-23) we are punting on that with the expectation that
175+
* eventually the scalar type for this dtype will be str.
176+
*/
166177
return val_obj;
167178
}
168179

0 commit comments

Comments
 (0)