Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions pandas/tests/arrays/string_/test_string.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import operator
"""
This module tests the functionality of StringArray and ArrowStringArray.
Tests for the str accessors are in pandas/tests/strings/test_string_array.py
"""

import numpy as np
import pytest
Expand Down Expand Up @@ -88,23 +91,6 @@ def test_setitem_with_scalar_string(dtype):
tm.assert_extension_array_equal(arr, expected)


@pytest.mark.parametrize(
"input, method",
[
(["a", "b", "c"], operator.methodcaller("capitalize")),
(["a b", "a bc. de"], operator.methodcaller("capitalize")),
],
)
def test_string_methods(input, method, dtype):
a = pd.Series(input, dtype=dtype)
b = pd.Series(input, dtype="object")
result = method(a.str)
expected = method(b.str)

assert result.dtype.name == dtype
tm.assert_series_equal(result.astype(object), expected)


def test_astype_roundtrip(dtype, request):
if dtype == "arrow_string":
reason = "ValueError: Could not convert object to NumPy datetime"
Expand Down
19 changes: 19 additions & 0 deletions pandas/tests/strings/test_string_array.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import operator

import numpy as np
import pytest

Expand Down Expand Up @@ -117,3 +119,20 @@ def test_str_get_stringarray_multiple_nans(nullable_string_dtype):
result = s.str.get(2)
expected = Series(pd.array([pd.NA, pd.NA, pd.NA, "c"], dtype=nullable_string_dtype))
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize(
"input, method",
[
(["a", "b", "c"], operator.methodcaller("capitalize")),
(["a b", "a bc. de"], operator.methodcaller("capitalize")),
],
)
def test_capitalize(input, method, nullable_string_dtype):
a = Series(input, dtype=nullable_string_dtype)
b = Series(input, dtype="object")
result = method(a.str)
expected = method(b.str)

assert result.dtype.name == nullable_string_dtype
tm.assert_series_equal(result.astype(object), expected)