Skip to content

Commit 2d2596c

Browse files
committed
add comments, fix PEP8 violations
1 parent 34f2d5f commit 2d2596c

File tree

8 files changed

+16
-35
lines changed

8 files changed

+16
-35
lines changed

doc/source/whatsnew/v0.20.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Backwards incompatible API changes
6262

6363
- ``CParserError`` has been renamed to ``ParserError`` in ``pd.read_csv`` and will be removed in the future (:issue:`12665`)
6464

65-
- ``inplace`` arguments now require a boolean value, else a ``ValueError`` is thrown (:issue:`14189`)
65+
- ``inplace`` arguments now require a boolean value, else a ``ValueError`` is raised (:issue:`14189`)
6666

6767

6868

pandas/core/categorical.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,8 @@ def as_ordered(self, inplace=False):
633633
Whether or not to set the ordered attribute inplace or return a copy
634634
of this categorical with ordered set to True
635635
"""
636-
return self.set_ordered(True, inplace=_validate_bool_type(inplace, 'inplace'))
636+
inplace = _validate_bool_type(inplace, 'inplace')
637+
return self.set_ordered(True, inplace=inplace)
637638

638639
def as_unordered(self, inplace=False):
639640
"""
@@ -645,7 +646,8 @@ def as_unordered(self, inplace=False):
645646
Whether or not to set the ordered attribute inplace or return a copy
646647
of this categorical with ordered set to False
647648
"""
648-
return self.set_ordered(False, inplace=_validate_bool_type(inplace, 'inplace'))
649+
inplace = _validate_bool_type(inplace, 'inplace')
650+
return self.set_ordered(False, inplace=inplace)
649651

650652
def _get_ordered(self):
651653
""" Gets the ordered attribute """

pandas/sparse/tests/test_list.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,6 @@ def test_getitem(self):
113113
tm.assert_almost_equal(splist[i], arr[i])
114114
tm.assert_almost_equal(splist[-i], arr[-i])
115115

116-
def test_validate_bool_args(self):
117-
invalid_values = [1, "True", [1,2,3], 5.0]
118-
lst = SparseList(self.na_data)
119-
for value in invalid_values:
120-
with tm.assertRaises(ValueError):
121-
lst.consolidate(inplace=value)
122-
123116

124117
if __name__ == '__main__':
125118
import nose

pandas/tests/frame/test_validate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
from pandas.core.frame import DataFrame
44

55
class TestDataFrameValidate(TestCase):
6+
"""Tests for error handling related to data types of method arguments."""
67

78
df = DataFrame({'a':[1,2], 'b':[3,4]})
89

910
def test_validate_bool_args(self):
11+
""" Tests for error handling related to boolean arguments. """
1012
invalid_values = [1, "True", [1,2,3], 5.0]
1113

1214
for value in invalid_values:

pandas/tests/series/test_validate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
from pandas.core.series import Series
44

55
class TestSeriesValidate(TestCase):
6+
"""Tests for error handling related to data types of method arguments."""
67

7-
s = Series([1,2,3,4,5])
8+
s = Series([1, 2, 3, 4, 5])
89

910
def test_validate_bool_args(self):
11+
""" Tests for error handling related to boolean arguments. """
1012
invalid_values = [1, "True", [1,2,3], 5.0]
1113

1214
for value in invalid_values:

pandas/tests/test_internals.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -297,28 +297,6 @@ def test_split_block_at(self):
297297
# bs = list(bblock.split_block_at('f'))
298298
# self.assertEqual(len(bs), 0)
299299

300-
def test_validate_bool_args(self):
301-
invalid_values = [1, "True", [1,2,3], 5.0]
302-
303-
for value in invalid_values:
304-
with self.assertRaises(ValueError):
305-
self.int_block.fillna(value=0,inplace=value)
306-
307-
with self.assertRaises(ValueError):
308-
self.int_block.replace(to_replace=0, value=1, inplace=value)
309-
310-
with self.assertRaises(ValueError):
311-
self.int_block.interpolate(inplace=value)
312-
313-
with self.assertRaises(ValueError):
314-
self.int_block._interpolate_with_fill(inplace=value)
315-
316-
with self.assertRaises(ValueError):
317-
self.int_block._interpolate(inplace=value)
318-
319-
with self.assertRaises(ValueError):
320-
self.int_block.replace(to_replace=1, value=0, inplace=value)
321-
322300

323301
class TestDatetimeBlock(tm.TestCase):
324302
_multiprocess_can_split_ = True

pandas/tests/types/test_validate.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
def test_validate_bool_type():
55
arg_names = ['inplace', 'copy']
66
invalid_values = [1, "True", [1,2,3], 5.0]
7+
valid_values = [True, False, None]
78

89
for name in arg_names:
910
for value in invalid_values:
10-
with tm.assertRaisesRegexp(ValueError, "For argument %s expected type bool, received type %s" % (name, type(value).__name__)):
11+
with tm.assertRaisesRegexp(ValueError, "For argument \"%s\" expected type bool, received type %s" % (name, type(value).__name__)):
1112
_validate_bool_type(value, name)
13+
14+
for value in valid_values:
15+
tm.assert_equal(_validate_bool_type(value, name), value)

pandas/types/validate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
def _validate_bool_type(value, arg_name):
44
if not (is_bool(value) or value is None):
5-
raise ValueError('For argument %s expected type bool, received type %s.' %\
5+
raise ValueError('For argument "%s" expected type bool, received type %s.' %\
66
(arg_name, type(value).__name__))
77
return value

0 commit comments

Comments
 (0)