(self)
| 698 | |
| 699 | @pytest.mark.filterwarnings(r"ignore:\w+ chararray \w+:DeprecationWarning") |
| 700 | def test_unique_1d(self): |
| 701 | |
| 702 | a = [5, 7, 1, 2, 1, 5, 7] * 10 |
| 703 | b = [1, 2, 5, 7] |
| 704 | i1 = [2, 3, 0, 1] |
| 705 | i2 = [2, 3, 0, 1, 0, 2, 3] * 10 |
| 706 | c = np.multiply([2, 1, 2, 2], 10) |
| 707 | |
| 708 | # test for numeric arrays |
| 709 | types = self.get_types() |
| 710 | for dt in types: |
| 711 | aa = np.array(a, dt) |
| 712 | bb = np.array(b, dt) |
| 713 | self.check_all(aa, bb, i1, i2, c, dt) |
| 714 | |
| 715 | # test for object arrays |
| 716 | dt = 'O' |
| 717 | aa = np.empty(len(a), dt) |
| 718 | aa[:] = a |
| 719 | bb = np.empty(len(b), dt) |
| 720 | bb[:] = b |
| 721 | self.check_all(aa, bb, i1, i2, c, dt) |
| 722 | |
| 723 | # test for structured arrays |
| 724 | dt = [('', 'i'), ('', 'i')] |
| 725 | aa = np.array(list(zip(a, a)), dt) |
| 726 | bb = np.array(list(zip(b, b)), dt) |
| 727 | self.check_all(aa, bb, i1, i2, c, dt) |
| 728 | |
| 729 | # test for ticket #2799 |
| 730 | aa = [1. + 0.j, 1 - 1.j, 1] |
| 731 | assert_array_equal( |
| 732 | np.sort(np.unique(aa)), |
| 733 | [1. - 1.j, 1.], |
| 734 | ) |
| 735 | |
| 736 | # test for ticket #4785 |
| 737 | a = [(1, 2), (1, 2), (2, 3)] |
| 738 | unq = [1, 2, 3] |
| 739 | inv = [[0, 1], [0, 1], [1, 2]] |
| 740 | a1 = unique(a) |
| 741 | assert_array_equal(a1, unq) |
| 742 | a2, a2_inv = unique(a, return_inverse=True) |
| 743 | assert_array_equal(a2, unq) |
| 744 | assert_array_equal(a2_inv, inv) |
| 745 | |
| 746 | # test for chararrays with return_inverse (gh-5099) |
| 747 | a = np.char.chararray(5) |
| 748 | a[...] = '' |
| 749 | a2, a2_inv = np.unique(a, return_inverse=True) |
| 750 | assert_array_equal(a2_inv, np.zeros(5)) |
| 751 | |
| 752 | # test for ticket #9137 |
| 753 | a = [] |
| 754 | a1_idx = np.unique(a, return_index=True)[1] |
| 755 | a2_inv = np.unique(a, return_inverse=True)[1] |
| 756 | a3_idx, a3_inv = np.unique(a, return_index=True, |
| 757 | return_inverse=True)[1:] |
nothing calls this directly
no test coverage detected