Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions asciidtype/asciidtype/src/dtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ new_asciidtype_instance(long size)
}

/*
* This is used to determine the correct dtype to return when operations mix
* dtypes (I think?). For now just return the first one.
* This is used to determine the correct dtype to return when dealing
* with a mix of different dtypes (for example when creating an array
* from a list of scalars). Always return the dtype with the biggest
* size.
*/
static ASCIIDTypeObject *
common_instance(ASCIIDTypeObject *dtype1, ASCIIDTypeObject *dtype2)
{
if (!PyObject_RichCompareBool((PyObject *)dtype1, (PyObject *)dtype2,
Py_EQ)) {
PyErr_SetString(
PyExc_RuntimeError,
"common_instance called on unequal ASCIIDType instances");
return NULL;
if (dtype1->size >= dtype2->size) {
Py_INCREF(dtype1);
return dtype1;
}
return dtype1;
Py_INCREF(dtype2);
return dtype2;
}

static PyArray_DTypeMeta *
Expand Down
9 changes: 9 additions & 0 deletions asciidtype/tests/test_asciidtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ def test_creation_with_explicit_dtype():
)


def test_creation_from_scalar():
data = [
ASCIIScalar("hello", ASCIIDType(6)),
ASCIIScalar("array", ASCIIDType(7)),
]
arr = np.array(data)
assert repr(arr) == ("array(['hello', 'array'], dtype=ASCIIDType(7))")


def test_creation_truncation():
inp = ["hello", "this", "is", "an", "array"]

Expand Down
2 changes: 2 additions & 0 deletions metadatadtype/metadatadtype/src/dtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ get_metadata(PyObject *scalar)
}

PyObject *metadata = dtype->metadata;
Py_DECREF(dtype);
if (metadata == NULL) {
return NULL;
}
Expand Down Expand Up @@ -87,6 +88,7 @@ new_metadatadtype_instance(PyObject *metadata)
static MetadataDTypeObject *
common_instance(MetadataDTypeObject *dtype1, MetadataDTypeObject *dtype2)
{
Py_INCREF(dtype1);
return dtype1;
}

Expand Down