(self)
| 834 | assert_array_equal(uniq, [1, 2, 3, 4]) |
| 835 | |
| 836 | def test_unique_axis_zeros(self): |
| 837 | # issue 15559 |
| 838 | single_zero = np.empty(shape=(2, 0), dtype=np.int8) |
| 839 | uniq, idx, inv, cnt = unique(single_zero, axis=0, return_index=True, |
| 840 | return_inverse=True, return_counts=True) |
| 841 | |
| 842 | # there's 1 element of shape (0,) along axis 0 |
| 843 | assert_equal(uniq.dtype, single_zero.dtype) |
| 844 | assert_array_equal(uniq, np.empty(shape=(1, 0))) |
| 845 | assert_array_equal(idx, np.array([0])) |
| 846 | assert_array_equal(inv, np.array([0, 0])) |
| 847 | assert_array_equal(cnt, np.array([2])) |
| 848 | |
| 849 | # there's 0 elements of shape (2,) along axis 1 |
| 850 | uniq, idx, inv, cnt = unique(single_zero, axis=1, return_index=True, |
| 851 | return_inverse=True, return_counts=True) |
| 852 | |
| 853 | assert_equal(uniq.dtype, single_zero.dtype) |
| 854 | assert_array_equal(uniq, np.empty(shape=(2, 0))) |
| 855 | assert_array_equal(idx, np.array([])) |
| 856 | assert_array_equal(inv, np.array([])) |
| 857 | assert_array_equal(cnt, np.array([])) |
| 858 | |
| 859 | # test a "complicated" shape |
| 860 | shape = (0, 2, 0, 3, 0, 4, 0) |
| 861 | multiple_zeros = np.empty(shape=shape) |
| 862 | for axis in range(len(shape)): |
| 863 | expected_shape = list(shape) |
| 864 | if shape[axis] == 0: |
| 865 | expected_shape[axis] = 0 |
| 866 | else: |
| 867 | expected_shape[axis] = 1 |
| 868 | |
| 869 | assert_array_equal(unique(multiple_zeros, axis=axis), |
| 870 | np.empty(shape=expected_shape)) |
| 871 | |
| 872 | def test_unique_masked(self): |
| 873 | # issue 8664 |
nothing calls this directly
no test coverage detected