Skip to content

Commit f0afc3b

Browse files
committed
ENH: don't repeat numerical types
1 parent 18bbf07 commit f0afc3b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

pandas/core/strings.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,22 @@ def str_repeat(arr, repeats):
345345
repeated : array
346346
"""
347347
if np.isscalar(repeats):
348-
f = lambda x: x * repeats
349-
return _na_map(f, arr)
348+
def rep(x):
349+
try:
350+
return str.__mul__(x, repeats)
351+
except TypeError:
352+
return unicode.__mul__(x, repeats)
353+
return _na_map(rep, arr)
350354
else:
355+
def rep(x, r):
356+
try:
357+
return str.__mul__(x, r)
358+
except TypeError:
359+
return unicode.__mul__(x, r)
351360
repeats = np.asarray(repeats, dtype=object)
352-
result = lib.vec_binop(arr, repeats, operator.mul)
361+
result = lib.vec_binop(arr, repeats, str.__mul__)
353362
return result
354363

355-
356364
def str_match(arr, pat):
357365
"""
358366
Find groups in each string (from beginning) using passed regular expression

pandas/tests/test_strings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ def test_repeat(self):
179179
exp = Series(['a', 'bb', NA, 'cccc', NA, 'dddddd'])
180180
tm.assert_series_equal(result, exp)
181181

182-
"""
183182
#mixed
184183
mixed = Series(['a', NA, 'b', True, datetime.today(), 'foo',
185184
None, 1, 2.])
@@ -188,7 +187,6 @@ def test_repeat(self):
188187
xp = ['aaa', NA, 'bbb', NA, NA, 'foofoofoo', NA, NA, NA]
189188
self.assert_(isinstance(rs, Series))
190189
tm.assert_almost_equal(rs, xp)
191-
"""
192190

193191
def test_match(self):
194192
values = Series(['fooBAD__barBAD', NA, 'foo'])

0 commit comments

Comments
 (0)