Skip to content

BUG: single group series should preserve group name #7313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2014
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