Skip to content

Commit 9669f3f

Browse files
committed
BUG: "Replaced isinstance with is_integer, and changed test_pad_width to use getattr"
1 parent 40a3188 commit 9669f3f

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

pandas/core/strings.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
is_object_dtype,
99
is_string_like,
1010
is_list_like,
11-
is_scalar)
11+
is_scalar,
12+
is_integer)
1213
from pandas.core.common import _values_from_object
1314

1415
from pandas.core.algorithms import take_1d
@@ -914,7 +915,7 @@ def str_pad(arr, width, side='left', fillchar=' '):
914915
if len(fillchar) != 1:
915916
raise TypeError('fillchar must be a character, not str')
916917

917-
if not isinstance(width, compat.integer_types):
918+
if not is_integer(width):
918919
msg = 'width must be of integer type, not {0}'
919920
raise TypeError(msg.format(type(width).__name__))
920921

pandas/tests/test_strings.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1605,13 +1605,12 @@ def test_pad_fillchar(self):
16051605

16061606
def test_pad_width(self):
16071607
values = Series(['1', '22', 'a', 'bb'])
1608-
string_methods = Series.str(values)
1608+
s = Series(values)
16091609

1610-
for f_name, f in Series.str.__dict__.items():
1611-
if f_name in ['center', 'ljust', 'rjust', 'zfill', 'pad']:
1612-
with tm.assertRaisesRegexp(TypeError,
1613-
"width must be of integer type,*"):
1614-
f(string_methods, 'f')
1610+
for f in ['center', 'ljust', 'rjust', 'zfill', 'pad']:
1611+
with tm.assertRaisesRegexp(TypeError,
1612+
"width must be of integer type, not*"):
1613+
getattr(s.str, f)('f')
16151614

16161615
def test_translate(self):
16171616

0 commit comments

Comments
 (0)