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

Already on GitHub? Sign in to your account

BUG: single group series should preserve group name #7313

Merged
merged 1 commit into from Jun 2, 2014
Jump to file or symbol
Failed to load files and symbols.
+11 −1
Split
View
@@ -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`).
View
@@ -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)
@@ -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('|')