Skip to content

Commit 29710a4

Browse files
committed
strings and bytes
1 parent b0cade6 commit 29710a4

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

tests/test_string_accessors.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_string_accessors_type_preserving_index() -> None:
7979
_check(assert_type(idx.str.zfill(10), "pd.Index[str]"))
8080

8181

82-
def test_string_accessors_type_boolean_series():
82+
def test_string_accessors_boolean_series():
8383
s = pd.Series(DATA)
8484
_check = functools.partial(check, klass=pd.Series, dtype=bool)
8585
_check(assert_type(s.str.startswith("a"), "pd.Series[bool]"))
@@ -107,7 +107,7 @@ def test_string_accessors_type_boolean_series():
107107
_check(assert_type(s.str.match("pp"), "pd.Series[bool]"))
108108

109109

110-
def test_string_accessors_type_boolean_index():
110+
def test_string_accessors_boolean_index():
111111
idx = pd.Index(DATA)
112112
_check = functools.partial(check, klass=np.ndarray, dtype=np.bool_)
113113
_check(assert_type(idx.str.startswith("a"), np_ndarray_bool))
@@ -135,7 +135,7 @@ def test_string_accessors_type_boolean_index():
135135
_check(assert_type(idx.str.match("pp"), np_ndarray_bool))
136136

137137

138-
def test_string_accessors_type_integer_series():
138+
def test_string_accessors_integer_series():
139139
s = pd.Series(DATA)
140140
_check = functools.partial(check, klass=pd.Series, dtype=np.integer)
141141
_check(assert_type(s.str.find("p"), "pd.Series[int]"))
@@ -146,7 +146,7 @@ def test_string_accessors_type_integer_series():
146146
_check(assert_type(s.str.len(), "pd.Series[int]"))
147147

148148

149-
def test_string_accessors_type_integer_index():
149+
def test_string_accessors_integer_index():
150150
idx = pd.Index(DATA)
151151
_check = functools.partial(check, klass=pd.Index, dtype=np.integer)
152152
_check(assert_type(idx.str.find("p"), "pd.Index[int]"))
@@ -157,19 +157,30 @@ def test_string_accessors_type_integer_index():
157157
_check(assert_type(idx.str.len(), "pd.Index[int]"))
158158

159159

160-
def test_string_accessors_encode_decode():
161-
s_str = pd.Series(["a1", "b2", "c3"])
162-
s_bytes = pd.Series([b"a1", b"b2", b"c3"])
160+
def test_string_accessors_string_series():
161+
s = pd.Series([b"a1", b"b2", b"c3"])
162+
_check = functools.partial(check, klass=pd.Series, dtype=str)
163+
_check(assert_type(s.str.decode("utf-8"), "pd.Series[str]"))
163164
s2 = pd.Series([["apple", "banana"], ["cherry", "date"], [1, "eggplant"]])
164-
check(
165-
assert_type(s_bytes.str.decode("utf-8"), "pd.Series[str]"),
166-
pd.Series,
167-
str,
168-
)
169-
check(
170-
assert_type(s_str.str.encode("latin-1"), "pd.Series[bytes]"), pd.Series, bytes
171-
)
172-
check(assert_type(s2.str.join("-"), "pd.Series[str]"), pd.Series, str)
165+
_check(assert_type(s2.str.join("-"), "pd.Series[str]"))
166+
167+
168+
def test_string_accessors_string_index():
169+
idx = pd.Index([b"a1", b"b2", b"c3"])
170+
_check = functools.partial(check, klass=pd.Index, dtype=str)
171+
_check(assert_type(idx.str.decode("utf-8"), "pd.Index[str]"))
172+
idx2 = pd.Index([["apple", "banana"], ["cherry", "date"], [1, "eggplant"]])
173+
_check(assert_type(idx2.str.join("-"), "pd.Index[str]"))
174+
175+
176+
def test_string_accessors_bytes_series():
177+
s = pd.Series(["a1", "b2", "c3"])
178+
check(assert_type(s.str.encode("latin-1"), "pd.Series[bytes]"), pd.Series, bytes)
179+
180+
181+
def test_string_accessors_bytes_index():
182+
s = pd.Index(["a1", "b2", "c3"])
183+
check(assert_type(s.str.encode("latin-1"), "pd.Index[bytes]"), pd.Index, bytes)
173184

174185

175186
def test_string_accessors_list():

0 commit comments

Comments
 (0)