Skip to content

Commit 77bbb5d

Browse files
[ArrowStringArray] CLN: move and rename test_string_methods (#40960)
1 parent 1234545 commit 77bbb5d

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

pandas/tests/arrays/string_/test_string.py

+4-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import operator
1+
"""
2+
This module tests the functionality of StringArray and ArrowStringArray.
3+
Tests for the str accessors are in pandas/tests/strings/test_string_array.py
4+
"""
25

36
import numpy as np
47
import pytest
@@ -88,23 +91,6 @@ def test_setitem_with_scalar_string(dtype):
8891
tm.assert_extension_array_equal(arr, expected)
8992

9093

91-
@pytest.mark.parametrize(
92-
"input, method",
93-
[
94-
(["a", "b", "c"], operator.methodcaller("capitalize")),
95-
(["a b", "a bc. de"], operator.methodcaller("capitalize")),
96-
],
97-
)
98-
def test_string_methods(input, method, dtype):
99-
a = pd.Series(input, dtype=dtype)
100-
b = pd.Series(input, dtype="object")
101-
result = method(a.str)
102-
expected = method(b.str)
103-
104-
assert result.dtype.name == dtype
105-
tm.assert_series_equal(result.astype(object), expected)
106-
107-
10894
def test_astype_roundtrip(dtype, request):
10995
if dtype == "arrow_string":
11096
reason = "ValueError: Could not convert object to NumPy datetime"

pandas/tests/strings/test_string_array.py

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import operator
2+
13
import numpy as np
24
import pytest
35

@@ -117,3 +119,20 @@ def test_str_get_stringarray_multiple_nans(nullable_string_dtype):
117119
result = s.str.get(2)
118120
expected = Series(pd.array([pd.NA, pd.NA, pd.NA, "c"], dtype=nullable_string_dtype))
119121
tm.assert_series_equal(result, expected)
122+
123+
124+
@pytest.mark.parametrize(
125+
"input, method",
126+
[
127+
(["a", "b", "c"], operator.methodcaller("capitalize")),
128+
(["a b", "a bc. de"], operator.methodcaller("capitalize")),
129+
],
130+
)
131+
def test_capitalize(input, method, nullable_string_dtype):
132+
a = Series(input, dtype=nullable_string_dtype)
133+
b = Series(input, dtype="object")
134+
result = method(a.str)
135+
expected = method(b.str)
136+
137+
assert result.dtype.name == nullable_string_dtype
138+
tm.assert_series_equal(result.astype(object), expected)

0 commit comments

Comments
 (0)