Skip to content

Commit 7f7f3d4

Browse files
Dr-Irvjreback
authored andcommitted
BUG: Series.is_unique has extra output if contains objects with __ne__ defined (#20691)
1 parent 0bd8a5a commit 7f7f3d4

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

doc/source/whatsnew/v0.23.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ Indexing
10761076
- Bug in :meth:`Index.difference` when taking difference of an ``Index`` with itself (:issue:`20040`)
10771077
- 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`).
10781078
- Bug in :class:`IntervalIndex` where some indexing operations were not supported for overlapping or non-monotonic ``uint64`` data (:issue:`20636`)
1079+
- Bug in ``Series.is_unique`` where extraneous output in stderr is shown if Series contains objects with ``__ne__`` defined (:issue:`20661`)
10791080

10801081
MultiIndex
10811082
^^^^^^^^^^

pandas/_libs/hashtable.pyx

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ from khash cimport (
3939
kh_put_pymap, kh_resize_pymap)
4040

4141

42-
from util cimport _checknan
4342
cimport util
4443

4544
from missing cimport checknull

pandas/_libs/hashtable_class_helper.pxi.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ cdef class PyObjectHashTable(HashTable):
870870
for i in range(n):
871871
val = values[i]
872872
hash(val)
873-
if not _checknan(val):
873+
if not checknull(val):
874874
k = kh_get_pymap(self.table, <PyObject*>val)
875875
if k == self.table.n_buckets:
876876
kh_put_pymap(self.table, <PyObject*>val, &ret)

pandas/_libs/src/util.pxd

-3
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,5 @@ cdef inline bint _checknull(object val):
159159
except ValueError:
160160
return False
161161

162-
cdef inline bint _checknan(object val):
163-
return not cnp.PyArray_Check(val) and val != val
164-
165162
cdef inline bint is_period_object(object val):
166163
return getattr(val, '_typ', '_typ') == 'period'

pandas/tests/series/test_analytics.py

+16
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,22 @@ def test_is_unique(self):
15941594
s = Series(np.arange(1000))
15951595
assert s.is_unique
15961596

1597+
def test_is_unique_class_ne(self, capsys):
1598+
# GH 20661
1599+
class Foo(object):
1600+
def __init__(self, val):
1601+
self._value = val
1602+
1603+
def __ne__(self, other):
1604+
raise Exception("NEQ not supported")
1605+
1606+
li = [Foo(i) for i in range(5)]
1607+
s = pd.Series(li, index=[i for i in range(5)])
1608+
_, err = capsys.readouterr()
1609+
s.is_unique
1610+
_, err = capsys.readouterr()
1611+
assert len(err) == 0
1612+
15971613
def test_is_monotonic(self):
15981614

15991615
s = Series(np.random.randint(0, 10, size=1000))

0 commit comments

Comments
 (0)