|
2 | 2 | import re
|
3 | 3 |
|
4 | 4 | import numpy as np
|
| 5 | +import numpy.typing as npt |
5 | 6 | import pandas as pd
|
6 | 7 | from typing_extensions import assert_type
|
7 | 8 |
|
8 | 9 | from tests import check
|
9 | 10 |
|
| 11 | +# Separately define here so pytest works |
| 12 | +np_ndarray_bool = npt.NDArray[np.bool_] |
| 13 | + |
| 14 | + |
10 | 15 | DATA = ["applep", "bananap", "Cherryp", "DATEp", "eGGpLANTp", "123p", "23.45p"]
|
11 | 16 |
|
12 | 17 |
|
@@ -105,29 +110,29 @@ def test_string_accessors_type_boolean_series():
|
105 | 110 | def test_string_accessors_type_boolean_index():
|
106 | 111 | idx = pd.Index(DATA)
|
107 | 112 | _check = functools.partial(check, klass=np.ndarray, dtype=np.bool_)
|
108 |
| - _check(assert_type(idx.str.startswith("a"), "npt.NDArray[np.bool_]")) |
| 113 | + _check(assert_type(idx.str.startswith("a"), np_ndarray_bool)) |
109 | 114 | _check(
|
110 |
| - assert_type(idx.str.startswith(("a", "b")), "npt.NDArray[np.bool_]"), |
| 115 | + assert_type(idx.str.startswith(("a", "b")), np_ndarray_bool), |
111 | 116 | )
|
112 | 117 | _check(
|
113 |
| - assert_type(idx.str.contains("a"), "npt.NDArray[np.bool_]"), |
| 118 | + assert_type(idx.str.contains("a"), np_ndarray_bool), |
114 | 119 | )
|
115 | 120 | _check(
|
116 |
| - assert_type(idx.str.contains(re.compile(r"a")), "npt.NDArray[np.bool_]"), |
| 121 | + assert_type(idx.str.contains(re.compile(r"a")), np_ndarray_bool), |
117 | 122 | )
|
118 |
| - _check(assert_type(idx.str.endswith("e"), "npt.NDArray[np.bool_]")) |
119 |
| - _check(assert_type(idx.str.endswith(("e", "f")), "npt.NDArray[np.bool_]")) |
120 |
| - _check(assert_type(idx.str.fullmatch("apple"), "npt.NDArray[np.bool_]")) |
121 |
| - _check(assert_type(idx.str.isalnum(), "npt.NDArray[np.bool_]")) |
122 |
| - _check(assert_type(idx.str.isalpha(), "npt.NDArray[np.bool_]")) |
123 |
| - _check(assert_type(idx.str.isdecimal(), "npt.NDArray[np.bool_]")) |
124 |
| - _check(assert_type(idx.str.isdigit(), "npt.NDArray[np.bool_]")) |
125 |
| - _check(assert_type(idx.str.isnumeric(), "npt.NDArray[np.bool_]")) |
126 |
| - _check(assert_type(idx.str.islower(), "npt.NDArray[np.bool_]")) |
127 |
| - _check(assert_type(idx.str.isspace(), "npt.NDArray[np.bool_]")) |
128 |
| - _check(assert_type(idx.str.istitle(), "npt.NDArray[np.bool_]")) |
129 |
| - _check(assert_type(idx.str.isupper(), "npt.NDArray[np.bool_]")) |
130 |
| - _check(assert_type(idx.str.match("pp"), "npt.NDArray[np.bool_]")) |
| 123 | + _check(assert_type(idx.str.endswith("e"), np_ndarray_bool)) |
| 124 | + _check(assert_type(idx.str.endswith(("e", "f")), np_ndarray_bool)) |
| 125 | + _check(assert_type(idx.str.fullmatch("apple"), np_ndarray_bool)) |
| 126 | + _check(assert_type(idx.str.isalnum(), np_ndarray_bool)) |
| 127 | + _check(assert_type(idx.str.isalpha(), np_ndarray_bool)) |
| 128 | + _check(assert_type(idx.str.isdecimal(), np_ndarray_bool)) |
| 129 | + _check(assert_type(idx.str.isdigit(), np_ndarray_bool)) |
| 130 | + _check(assert_type(idx.str.isnumeric(), np_ndarray_bool)) |
| 131 | + _check(assert_type(idx.str.islower(), np_ndarray_bool)) |
| 132 | + _check(assert_type(idx.str.isspace(), np_ndarray_bool)) |
| 133 | + _check(assert_type(idx.str.istitle(), np_ndarray_bool)) |
| 134 | + _check(assert_type(idx.str.isupper(), np_ndarray_bool)) |
| 135 | + _check(assert_type(idx.str.match("pp"), np_ndarray_bool)) |
131 | 136 |
|
132 | 137 |
|
133 | 138 | def test_string_accessors_type_integer_series():
|
|
0 commit comments