diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index 1f75de598330d..32166db08f8ad 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -1068,6 +1068,7 @@ Indexing - Bug in :meth:`Index.difference` when taking difference of an ``Index`` with itself (:issue:`20040`) - Bug in :meth:`DataFrame.first_valid_index` and :meth:`DataFrame.last_valid_index` in presence of entire rows of NaNs in the middle of values (:issue:`20499`). - Bug in :class:`IntervalIndex` where some indexing operations were not supported for overlapping or non-monotonic ``uint64`` data (:issue:`20636`) +- Bug in ``Series.is_unique`` where extraneous output in stderr is shown if Series contains objects with ``__ne__`` defined (:issue:`20661`) MultiIndex ^^^^^^^^^^ diff --git a/pandas/_libs/hashtable.pyx b/pandas/_libs/hashtable.pyx index 15d93374da3a9..b9a72a0c8285f 100644 --- a/pandas/_libs/hashtable.pyx +++ b/pandas/_libs/hashtable.pyx @@ -39,7 +39,6 @@ from khash cimport ( kh_put_pymap, kh_resize_pymap) -from util cimport _checknan cimport util from missing cimport checknull diff --git a/pandas/_libs/hashtable_class_helper.pxi.in b/pandas/_libs/hashtable_class_helper.pxi.in index eca66f78499db..dbeb8bda3e454 100644 --- a/pandas/_libs/hashtable_class_helper.pxi.in +++ b/pandas/_libs/hashtable_class_helper.pxi.in @@ -870,7 +870,7 @@ cdef class PyObjectHashTable(HashTable): for i in range(n): val = values[i] hash(val) - if not _checknan(val): + if not checknull(val): k = kh_get_pymap(self.table, val) if k == self.table.n_buckets: kh_put_pymap(self.table, val, &ret) diff --git a/pandas/_libs/src/util.pxd b/pandas/_libs/src/util.pxd index 5030b742849f8..d8249ec130f4d 100644 --- a/pandas/_libs/src/util.pxd +++ b/pandas/_libs/src/util.pxd @@ -159,8 +159,5 @@ cdef inline bint _checknull(object val): except ValueError: return False -cdef inline bint _checknan(object val): - return not cnp.PyArray_Check(val) and val != val - cdef inline bint is_period_object(object val): return getattr(val, '_typ', '_typ') == 'period' diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index f93aaf2115601..6ea40329f4bc3 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -1594,6 +1594,22 @@ def test_is_unique(self): s = Series(np.arange(1000)) assert s.is_unique + def test_is_unique_class_ne(self, capsys): + # GH 20661 + class Foo(object): + def __init__(self, val): + self._value = val + + def __ne__(self, other): + raise Exception("NEQ not supported") + + li = [Foo(i) for i in range(5)] + s = pd.Series(li, index=[i for i in range(5)]) + _, err = capsys.readouterr() + s.is_unique + _, err = capsys.readouterr() + assert len(err) == 0 + def test_is_monotonic(self): s = Series(np.random.randint(0, 10, size=1000))