Repository: numpy/numpy
File: numpy/_core/tests/test_defchararray.py (Python)

Code before:
        assert_array_equal(A.endswith(' '), [[1, 0], [0, 0], [1, 0]])
        assert_array_equal(A.endswith('3', 0, 3), [[0, 0], [1, 0], [1, 0]])

        def fail():
            A.endswith('3', 'fdjk')

        assert_raises(TypeError, fail)

    @pytest.mark.parametrize(
        "dtype, encode",
        [("U", str),
         ("S", lambda x: x.encode('ascii')),
         ])
    def test_find(self, dtype, encode):
        A = self.A().astype(dtype)
        assert_(issubclass(A.find(encode('a')).dtype.type, np.integer))
        assert_array_equal(A.find(encode('a')),
                           [[1, -1], [-1, 6], [-1, -1]])
        assert_array_equal(A.find(encode('3')),
                           [[-1, -1], [2, -1], [2, -1]])
        assert_array_equal(A.find(encode('a'), 0, 2),
                           [[1, -1], [-1, -1], [-1, -1]])
        assert_array_equal(A.find([encode('1'), encode('P')]),
                           [[-1, -1], [0, -1], [0, 1]])
        C = (np.array(['ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                            '01234567890123456789012345'])
                  .view(np.char.chararray)).astype(dtype)
        assert_array_equal(C.find(encode('M')), [12, -1])

    def test_index(self):
        A = self.A()

        def fail():
            A.index('a')

        assert_raises(ValueError, fail)
        assert_(np.char.index('abcba', 'b') == 1)
        assert_(issubclass(np.char.index('abcba', 'b').dtype.type, np.integer))

    def test_isalnum(self):
        A = self.A()
        assert_(issubclass(A.isalnum().dtype.type, np.bool))
        assert_array_equal(A.isalnum(), [[False, False], [True, True], [False, True]])

    def test_isalpha(self):
        A = self.A()
        assert_(issubclass(A.isalpha().dtype.type, np.bool))
        assert_array_equal(A.isalpha(), [[False, False], [False, True], [False, True]])

    def test_isdigit(self):
        A = self.A()

Review comment (suggestion):
Let's make this line up too

```suggestion
        C = (np.array(['ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                       '01234567890123456789012345'])
```

Code after:

        def fail():
            A.endswith('3', 'fdjk')

        assert_raises(TypeError, fail)

    @pytest.mark.parametrize(
        "dtype, encode",
        [("U", str),
         ("S", lambda x: x.encode('ascii')),
         ])
    def test_find(self, dtype, encode):
        A = self.A().astype(dtype)
        assert_(issubclass(A.find(encode('a')).dtype.type, np.integer))
        assert_array_equal(A.find(encode('a')),
                           [[1, -1], [-1, 6], [-1, -1]])
        assert_array_equal(A.find(encode('3')),
                           [[-1, -1], [2, -1], [2, -1]])
        assert_array_equal(A.find(encode('a'), 0, 2),
                           [[1, -1], [-1, -1], [-1, -1]])
        assert_array_equal(A.find([encode('1'), encode('P')]),
                           [[-1, -1], [0, -1], [0, 1]])
        C = (np.array(['ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                       '01234567890123456789012345'])
                       .view(np.char.chararray)).astype(dtype)
        assert_array_equal(C.find(encode('M')), [12, -1])

    def test_index(self):
        A = self.A()

        def fail():
            A.index('a')

        assert_raises(ValueError, fail)
        assert_(np.char.index('abcba', 'b') == 1)
        assert_(issubclass(np.char.index('abcba', 'b').dtype.type, np.integer))

    def test_isalnum(self):
        A = self.A()
        assert_(issubclass(A.isalnum().dtype.type, np.bool))
        assert_array_equal(A.isalnum(), [[False, False], [True, True], [False, True]])

    def test_isalpha(self):
        A = self.A()
        assert_(issubclass(A.isalpha().dtype.type, np.bool))
        assert_array_equal(A.isalpha(), [[False, False], [False, True], [False, True]])

    def test_isdigit(self):
        A = self.A()
        assert_(issubclass(A.isdigit().dtype.type, np.bool))
        assert_array_equal(A.isdigit(), [[False, False], [True, False], [False, False]])