Skip to content

Commit 4f49001

Browse files
committed
BUG: check for errors / clear errors inside khash with PyObject* close #1318
1 parent e1ff90c commit 4f49001

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

RELEASE.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ Where to get it
2222
* Binary installers on PyPI: http://pypi.python.org/pypi/pandas
2323
* Documentation: http://pandas.pydata.org
2424

25+
pandas 0.8.1
26+
============
27+
28+
**Release date:** NOT YET RELEASED
29+
30+
**Bug fixes**
31+
32+
- Handle TypeError issues inside PyObject_RichCompareBool calls in khash
33+
(#1318)
34+
2535
pandas 0.8.0
2636
============
2737

pandas/core/groupby.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import types
33
import numpy as np
44

5-
from pandas.core.algorithms import unique
6-
from pandas.core.categorical import Factor
5+
from pandas.core.categorical import Categorical
76
from pandas.core.frame import DataFrame
87
from pandas.core.generic import NDFrame
98
from pandas.core.index import Index, MultiIndex, _ensure_index
@@ -971,7 +970,7 @@ def __init__(self, index, grouper=None, name=None, level=None,
971970
else:
972971
if isinstance(self.grouper, (list, tuple)):
973972
self.grouper = com._asarray_tuplesafe(self.grouper)
974-
elif isinstance(self.grouper, Factor):
973+
elif isinstance(self.grouper, Categorical):
975974
factor = self.grouper
976975
self._was_factor = True
977976

pandas/src/khash.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,21 +574,33 @@ typedef const char *kh_cstr_t;
574574

575575
#include <Python.h>
576576

577+
int PANDAS_INLINE pyobject_cmp(PyObject* a, PyObject* b) {
578+
int result = PyObject_RichCompareBool(a, b, Py_EQ);
579+
if (result < 0) {
580+
PyErr_Clear();
581+
return 0;
582+
}
583+
return result;
584+
}
585+
586+
577587
#define kh_python_hash_func(key) (PyObject_Hash(key))
578-
#define kh_python_hash_equal(a, b) ((a == b) || PyObject_RichCompareBool(a, b, Py_EQ))
588+
#define kh_python_hash_equal(a, b) (pyobject_cmp(a, b))
579589

580590

581591
// Python object
582592

583593
typedef PyObject* kh_pyobject_t;
584594

585-
#define KHASH_MAP_INIT_PYOBJECT(name, khval_t) \
586-
KHASH_INIT(name, kh_pyobject_t, khval_t, 1, kh_python_hash_func, kh_python_hash_equal)
595+
#define KHASH_MAP_INIT_PYOBJECT(name, khval_t) \
596+
KHASH_INIT(name, kh_pyobject_t, khval_t, 1, \
597+
kh_python_hash_func, kh_python_hash_equal)
587598

588599
KHASH_MAP_INIT_PYOBJECT(pymap, Py_ssize_t)
589600

590601
#define KHASH_SET_INIT_PYOBJECT(name) \
591-
KHASH_INIT(name, kh_pyobject_t, char, 0, kh_python_hash_func, kh_python_hash_equal)
602+
KHASH_INIT(name, kh_pyobject_t, char, 0, \
603+
kh_python_hash_func, kh_python_hash_equal)
592604

593605
KHASH_SET_INIT_PYOBJECT(pyset)
594606

0 commit comments

Comments
 (0)