test_is_unique.py 937 B

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