zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import numpy as np
import pytest
 
from pandas import Series
 
 
@pytest.mark.parametrize(
    "data, expected",
    [
        (np.random.randint(0, 10, size=1000), False),
        (np.arange(1000), True),
        ([], True),
        ([np.nan], True),
        (["foo", "bar", np.nan], True),
        (["foo", "foo", np.nan], False),
        (["foo", "bar", np.nan, np.nan], False),
    ],
)
def test_is_unique(data, expected):
    # GH#11946 / GH#25180
    ser = Series(data)
    assert ser.is_unique is expected
 
 
def test_is_unique_class_ne(capsys):
    # GH#20661
    class Foo:
        def __init__(self, val) -> None:
            self._value = val
 
        def __ne__(self, other):
            raise Exception("NEQ not supported")
 
    with capsys.disabled():
        li = [Foo(i) for i in range(5)]
        ser = Series(li, index=list(range(5)))
 
    ser.is_unique
    captured = capsys.readouterr()
    assert len(captured.err) == 0