Skip to content

Commit 2463ce9

Browse files
committed
integer return type
1 parent 412b1ab commit 2463ce9

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

tests/test_string_accessors.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88
from tests import check
99

10+
DATA = ["applep", "bananap", "Cherryp", "DATEp", "eGGpLANTp", "123p", "23.45p"]
11+
1012

1113
def test_string_accessors_type_preserving_series() -> None:
12-
data = ["applep", "bananap", "Cherryp", "DATEp", "eGGpLANTp", "123p", "23.45p"]
13-
s = pd.Series(data)
14+
s = pd.Series(DATA)
1415
_check = functools.partial(check, klass=pd.Series, dtype=str)
1516
_check(assert_type(s.str.capitalize(), "pd.Series[str]"))
1617
_check(assert_type(s.str.casefold(), "pd.Series[str]"))
@@ -42,8 +43,7 @@ def test_string_accessors_type_preserving_series() -> None:
4243

4344

4445
def test_string_accessors_type_preserving_index() -> None:
45-
data = ["applep", "bananap", "Cherryp", "DATEp", "eGGpLANTp", "123p", "23.45p"]
46-
idx = pd.Index(data)
46+
idx = pd.Index(DATA)
4747
_check = functools.partial(check, klass=pd.Index, dtype=str)
4848
_check(assert_type(idx.str.capitalize(), "pd.Index[str]"))
4949
_check(assert_type(idx.str.casefold(), "pd.Index[str]"))
@@ -75,8 +75,7 @@ def test_string_accessors_type_preserving_index() -> None:
7575

7676

7777
def test_string_accessors_type_boolean_series():
78-
data = ["applep", "bananap", "Cherryp", "DATEp", "eGGpLANTp", "123p", "23.45p"]
79-
s = pd.Series(data)
78+
s = pd.Series(DATA)
8079
_check = functools.partial(check, klass=pd.Series, dtype=bool)
8180
_check(assert_type(s.str.startswith("a"), "pd.Series[bool]"))
8281
_check(
@@ -104,8 +103,7 @@ def test_string_accessors_type_boolean_series():
104103

105104

106105
def test_string_accessors_type_boolean_index():
107-
data = ["applep", "bananap", "Cherryp", "DATEp", "eGGpLANTp", "123p", "23.45p"]
108-
idx = pd.Index(data)
106+
idx = pd.Index(DATA)
109107
_check = functools.partial(check, klass=np.ndarray, dtype=np.bool_)
110108
_check(assert_type(idx.str.startswith("a"), "npt.NDArray[np.bool_]"))
111109
_check(
@@ -132,16 +130,26 @@ def test_string_accessors_type_boolean_index():
132130
_check(assert_type(idx.str.match("pp"), "npt.NDArray[np.bool_]"))
133131

134132

135-
def test_string_accessors_type_integer():
136-
s = pd.Series(
137-
["applep", "bananap", "Cherryp", "DATEp", "eGGpLANTp", "123p", "23.45p"]
138-
)
139-
check(assert_type(s.str.find("p"), "pd.Series[int]"), pd.Series, np.int64)
140-
check(assert_type(s.str.index("p"), "pd.Series[int]"), pd.Series, np.int64)
141-
check(assert_type(s.str.rfind("e"), "pd.Series[int]"), pd.Series, np.int64)
142-
check(assert_type(s.str.rindex("p"), "pd.Series[int]"), pd.Series, np.int64)
143-
check(assert_type(s.str.count("pp"), "pd.Series[int]"), pd.Series, np.integer)
144-
check(assert_type(s.str.len(), "pd.Series[int]"), pd.Series, np.integer)
133+
def test_string_accessors_type_integer_series():
134+
s = pd.Series(DATA)
135+
_check = functools.partial(check, klass=pd.Series, dtype=np.integer)
136+
_check(assert_type(s.str.find("p"), "pd.Series[int]"))
137+
_check(assert_type(s.str.index("p"), "pd.Series[int]"))
138+
_check(assert_type(s.str.rfind("e"), "pd.Series[int]"))
139+
_check(assert_type(s.str.rindex("p"), "pd.Series[int]"))
140+
_check(assert_type(s.str.count("pp"), "pd.Series[int]"))
141+
_check(assert_type(s.str.len(), "pd.Series[int]"))
142+
143+
144+
def test_string_accessors_type_integer_index():
145+
idx = pd.Index(DATA)
146+
_check = functools.partial(check, klass=pd.Index, dtype=np.integer)
147+
_check(assert_type(idx.str.find("p"), "pd.Index[int]"))
148+
_check(assert_type(idx.str.index("p"), "pd.Index[int]"))
149+
_check(assert_type(idx.str.rfind("e"), "pd.Index[int]"))
150+
_check(assert_type(idx.str.rindex("p"), "pd.Index[int]"))
151+
_check(assert_type(idx.str.count("pp"), "pd.Index[int]"))
152+
_check(assert_type(idx.str.len(), "pd.Index[int]"))
145153

146154

147155
def test_string_accessors_encode_decode():

0 commit comments

Comments
 (0)