Skip to content

Commit 8087551

Browse files
committed
fix tuple-case
1 parent a11463b commit 8087551

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/_libs/src/klib/khash_python.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,24 @@ int PANDAS_INLINE complexobject_cmp(PyObject* a, PyObject* b){
190190
);
191191
}
192192

193+
int PANDAS_INLINE pyobject_cmp(PyObject* a, PyObject* b);
194+
195+
196+
int PANDAS_INLINE tupleobject_cmp(PyObject* a, PyObject* b){
197+
Py_ssize_t i;
198+
199+
if (Py_SIZE(a) != Py_SIZE(b)) {
200+
return 0;
201+
}
202+
203+
for (i = 0; i < Py_SIZE(a); ++i) {
204+
if (!pyobject_cmp(PyTuple_GET_ITEM(a, i), PyTuple_GET_ITEM(b, i))) {
205+
return 0;
206+
}
207+
}
208+
return 1;
209+
}
210+
193211

194212
int PANDAS_INLINE pyobject_cmp(PyObject* a, PyObject* b) {
195213
int result = PyObject_RichCompareBool(a, b, Py_EQ);
@@ -207,6 +225,9 @@ int PANDAS_INLINE pyobject_cmp(PyObject* a, PyObject* b) {
207225
if (PyComplex_CheckExact(a)) {
208226
return complexobject_cmp(a, b);
209227
}
228+
if (PyTuple_CheckExact(a)) {
229+
return tupleobject_cmp(a, b);
230+
}
210231
}
211232
return result;
212233
}

0 commit comments

Comments
 (0)