Skip to content

Commit

Permalink
MAINT: Make argument determination in NameValidator more precise.
Browse files Browse the repository at this point in the history
The function was useing `'u' in case_sensitive` to detect `upper`.
Make that more precise with `case_sensitive.startswith('u').

Raise ValueError if case_sensitive has unrecognized value.
  • Loading branch information
charris committed Jan 23, 2015
1 parent 4b1aab3 commit 6bb48b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions numpy/lib/_iotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,13 @@ def __init__(self, excludelist=None, deletechars=None,
# Process the case option .....
if (case_sensitive is None) or (case_sensitive is True):
self.case_converter = lambda x: x
elif (case_sensitive is False) or ('u' in case_sensitive):
elif (case_sensitive is False) or case_sensitive.startswith('u'):
self.case_converter = lambda x: x.upper()
elif 'l' in case_sensitive:
elif case_sensitive.startswith('l'):
self.case_converter = lambda x: x.lower()
else:
self.case_converter = lambda x: x
msg = 'unrecognized case_sensitive value %s.' % case_sensitive
raise ValueError(msg)
#
self.replace_space = replace_space

Expand Down
6 changes: 5 additions & 1 deletion numpy/lib/tests/test__iotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import numpy as np
from numpy.compat import asbytes, asbytes_nested
from numpy.testing import (
run_module_suite, TestCase, assert_, assert_equal, assert_allclose
run_module_suite, TestCase, assert_, assert_equal, assert_allclose,
assert_raises
)
from numpy.lib._iotools import (
LineSplitter, NameValidator, StringConverter,
Expand Down Expand Up @@ -93,6 +94,9 @@ def test_case_sensitivity(self):
test = NameValidator(case_sensitive='lower').validate(names)
assert_equal(test, ['a', 'a_1', 'b', 'c'])

# check exceptions
assert_raises(ValueError, NameValidator, case_sensitive='foobar')

def test_excludelist(self):
"Test excludelist"
names = ['dates', 'data', 'Other Data', 'mask']
Expand Down

0 comments on commit 6bb48b0

Please sign in to comment.