7
7
8
8
from tests import check
9
9
10
+ DATA = ["applep" , "bananap" , "Cherryp" , "DATEp" , "eGGpLANTp" , "123p" , "23.45p" ]
11
+
10
12
11
13
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 )
14
15
_check = functools .partial (check , klass = pd .Series , dtype = str )
15
16
_check (assert_type (s .str .capitalize (), "pd.Series[str]" ))
16
17
_check (assert_type (s .str .casefold (), "pd.Series[str]" ))
@@ -42,8 +43,7 @@ def test_string_accessors_type_preserving_series() -> None:
42
43
43
44
44
45
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 )
47
47
_check = functools .partial (check , klass = pd .Index , dtype = str )
48
48
_check (assert_type (idx .str .capitalize (), "pd.Index[str]" ))
49
49
_check (assert_type (idx .str .casefold (), "pd.Index[str]" ))
@@ -75,8 +75,7 @@ def test_string_accessors_type_preserving_index() -> None:
75
75
76
76
77
77
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 )
80
79
_check = functools .partial (check , klass = pd .Series , dtype = bool )
81
80
_check (assert_type (s .str .startswith ("a" ), "pd.Series[bool]" ))
82
81
_check (
@@ -104,8 +103,7 @@ def test_string_accessors_type_boolean_series():
104
103
105
104
106
105
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 )
109
107
_check = functools .partial (check , klass = np .ndarray , dtype = np .bool_ )
110
108
_check (assert_type (idx .str .startswith ("a" ), "npt.NDArray[np.bool_]" ))
111
109
_check (
@@ -132,16 +130,26 @@ def test_string_accessors_type_boolean_index():
132
130
_check (assert_type (idx .str .match ("pp" ), "npt.NDArray[np.bool_]" ))
133
131
134
132
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]" ))
145
153
146
154
147
155
def test_string_accessors_encode_decode ():
0 commit comments