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
3 changes: 2 additions & 1 deletion pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,11 +884,12 @@ def _str_extract_noexpand(arr, pat, flags=0):
if arr.empty:
result = DataFrame(columns=columns, dtype=object)
else:
dtype = _result_dtype(arr)
result = DataFrame(
[groups_or_na(val) for val in arr],
columns=columns,
index=arr.index,
dtype=object,
dtype=dtype,
)
return result, name

Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3573,3 +3573,18 @@ def test_string_array_boolean_array(method, expected):
result = getattr(s.str, method)()
expected = Series(expected, dtype="boolean")
tm.assert_series_equal(result, expected)


def test_string_array_extract():
# https://github.com/pandas-dev/pandas/issues/30969
# Only expand=False & multiple groups was failing
a = Series(["a1", "b2", "cc"], dtype="string")
b = Series(["a1", "b2", "cc"], dtype="object")
pat = r"(\w)(\d)"

result = a.str.extract(pat, expand=False)
expected = b.str.extract(pat, expand=False)
assert all(result.dtypes == "string")

result = result.astype(object)
tm.assert_equal(result, expected)