Repository: numpy/numpy
File: numpy/lib/tests/test_function_base.py (Python)

Code before:
    def _create_arrays(self):
        a = np.arange(5)
        nd_a = np.arange(5).repeat(2).reshape(1, 5, 2)
        return a, nd_a

    def _check_inverse_of_slicing(self, indices):
        a, nd_a = self._create_arrays()
        a_del = delete(a, indices)
        nd_a_del = delete(nd_a, indices, axis=1)
        msg = f'Delete failed for obj: {indices!r}'
        assert_array_equal(setxor1d(a_del, a[indices, ]), a,
                           err_msg=msg)
        xor = setxor1d(nd_a_del[0, :, 0], nd_a[0, indices, 0])
        assert_array_equal(xor, nd_a[0, :, 0], err_msg=msg)

    def test_slices(self):
        lims = [-6, -2, 0, 1, 2, 4, 5]
        steps = [-3, -1, 1, 3]
        for start in lims:
            for stop in lims:
                for step in steps:
                    s = slice(start, stop, step)
                    self._check_inverse_of_slicing(s)

    def test_fancy(self):
        a = self._create_arrays()[0]
        self._check_inverse_of_slicing(np.array([[0, 1], [2, 1]]))
        with pytest.raises(IndexError):
            delete(a, [100])
        with pytest.raises(IndexError):
            delete(a, [-100])

        self._check_inverse_of_slicing([0, -1, 2, 2])

        self._check_inverse_of_slicing([True, False, False, True, False])

        # not legal, indexing with these would change the dimension
        with pytest.raises(ValueError):
            delete(a, True)
        with pytest.raises(ValueError):
            delete(a, False)

        # not enough items
        with pytest.raises(ValueError):
            delete(a, [False] * 4)

    def test_single(self):
        self._check_inverse_of_slicing(0)
        self._check_inverse_of_slicing(-4)

    def test_0d(self):

Review comment (suggestion):
Total nit, but I find this a little bit easier to read on the first pass - my eyes often skip the array indexing:

```suggestion
        a, _ = self._create_arrays()
```

Code after:
    def _create_arrays(self):
        a = np.arange(5)
        nd_a = np.arange(5).repeat(2).reshape(1, 5, 2)
        return a, nd_a

    def _check_inverse_of_slicing(self, indices):
        a, nd_a = self._create_arrays()
        a_del = delete(a, indices)
        nd_a_del = delete(nd_a, indices, axis=1)
        msg = f'Delete failed for obj: {indices!r}'
        assert_array_equal(setxor1d(a_del, a[indices, ]), a,
                           err_msg=msg)
        xor = setxor1d(nd_a_del[0, :, 0], nd_a[0, indices, 0])
        assert_array_equal(xor, nd_a[0, :, 0], err_msg=msg)

    def test_slices(self):
        lims = [-6, -2, 0, 1, 2, 4, 5]
        steps = [-3, -1, 1, 3]
        for start in lims:
            for stop in lims:
                for step in steps:
                    s = slice(start, stop, step)
                    self._check_inverse_of_slicing(s)

    def test_fancy(self):
        a, _ = self._create_arrays()
        self._check_inverse_of_slicing(np.array([[0, 1], [2, 1]]))
        with pytest.raises(IndexError):
            delete(a, [100])
        with pytest.raises(IndexError):
            delete(a, [-100])

        self._check_inverse_of_slicing([0, -1, 2, 2])

        self._check_inverse_of_slicing([True, False, False, True, False])

        # not legal, indexing with these would change the dimension
        with pytest.raises(ValueError):
            delete(a, True)
        with pytest.raises(ValueError):
            delete(a, False)

        # not enough items
        with pytest.raises(ValueError):
            delete(a, [False] * 4)

    def test_single(self):
        self._check_inverse_of_slicing(0)
        self._check_inverse_of_slicing(-4)

    def test_0d(self):