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
2 changes: 2 additions & 0 deletions doc/source/v0.14.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ Bug Fixes
- Bug in ``Float64Index`` which didn't allow duplicates (:issue:`7149`).
- Bug in ``DataFrame.replace()`` where truthy values were being replaced
(:issue:`7140`).
- Bug in ``StringMethods.extract()`` where a single match group Series
would use the matcher's name instead of the group name (:issue:`7313`).
3 changes: 2 additions & 1 deletion pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,8 +906,9 @@ def _wrap_result(self, result):
if not hasattr(result, 'ndim'):
return result
elif result.ndim == 1:
name = getattr(result, 'name', None)
return Series(result, index=self.series.index,
name=self.series.name)
name=name or self.series.name)
else:
assert result.ndim < 3
return DataFrame(result, index=self.series.index)
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,13 @@ def check_index(index):
tm.makeDateIndex, tm.makePeriodIndex ]:
check_index(index())

def test_extract_single_series_name_is_preserved(self):
s = Series(['a3', 'b3', 'c2'], name='bob')
r = s.str.extract(r'(?P<sue>[a-z])')
e = Series(['a', 'b', 'c'], name='sue')
tm.assert_series_equal(r, e)
self.assertEqual(r.name, e.name)

def test_get_dummies(self):
s = Series(['a|b', 'a|c', np.nan])
result = s.str.get_dummies('|')
Expand Down